Jump to content

setVisible with php


swamp

Recommended Posts

Hi there, I've got this code splitting the $post into divs containing 900 characters each...

 

<?
$i=-1;
for($t=0; $t<strlen($post);$t++){
if($t%904==0) $i++;
$out[$i].=$post{$t};
}
?>

<?
foreach($out as $k=>$v) $out[$k]='<div id="content_'.$k.'">'.$v."</div>";
$out=implode('',$out);

echo nl2br($out);
?>

 

I'm using java to flick through the divs, showing only one at a time, like pages (without changing the whole file)

 

<p><span class="arrow-back"><a href="#" onclick="setVisible('content_0>');">previous page</a></span>
<span class="arrow"><a href="#" onclick="setVisible('content_1>');">next page</a></span></p>

 

I need the arrows that setVisibile('content_NUMBER') to work out which div you're currently in and then give you next and back so in div 3 you could go back to div 2 or forward to div 4...

 

Any help? thanks!

Link to comment
Share on other sites

How about like this?

<html>
<head>
<script type="text/javascript">
function showNext(e)
{
e.style.display='none';
e.nextSibling.style.display='block';
}
function showPrev(e)
{
e.style.display='none';
e.previousSibling.style.display='block';
}
</script>
</head>

<body>

</body>
</html>
<?php
$string = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Proin feugiat. Sed ac quam. Praesent ut diam tristique urna malesuada sollicitudin. Integer imperdiet vestibulum metus. Mauris est. Cras ac nibh. Nullam dictum, ante aliquet ornare adipiscing, pede augue imperdiet eros, eget dictum tortor lacus ut neque. Cras libero velit, rutrum ultrices, elementum non, tincidunt eget, tortor. Aliquam auctor arcu ac pede. Nulla hendrerit est vitae pede. Integer magna pede, imperdiet pulvinar, lacinia id, ultrices et, sapien. Proin lobortis enim at lorem. Aliquam tincidunt. Aenean sit amet erat. Quisque blandit. In hac habitasse platea dictumst. 
Phasellus eu sem vel ligula condimentum tincidunt. Donec vitae mi sed nulla adipiscing aliquet. Duis tempus. Vestibulum vestibulum, augue eget interdum mattis, nibh libero adipiscing risus, ut rhoncus lacus nunc eget dui. Suspendisse potenti. Praesent mauris. Proin ullamcorper volutpat nibh. Vivamus et erat. Sed hendrerit dignissim erat. Suspendisse potenti. Mauris id quam. Curabitur felis felis, laoreet ut, tempor nec, posuere quis, nisl. Integer egestas urna ac mauris. Donec tincidunt ligula non nisi. Etiam vitae odio. Morbi sed lectus. 
Ut dui dolor, egestas non, pretium id, lacinia sed, justo. Aenean non pede. Aenean ullamcorper massa eu risus. Praesent arcu orci, rutrum sagittis, suscipit ut, imperdiet sit amet, sapien. Donec in sapien. Proin blandit cursus elit. Quisque sed tellus. Sed interdum massa a magna. In hac habitasse platea dictumst. Integer sapien neque, ultricies sed, eleifend sed, pharetra eget, leo. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec egestas nulla et sapien. Aliquam ultrices viverra elit. Aenean vitae metus. Donec nisi. Vivamus quis purus. Morbi a tortor. Ut erat lorem, pharetra ac, vehicula ut, viverra non, tortor. Duis pellentesque odio in nibh. Aenean egestas ultricies lectus. ";
$max = 900;
echo "<div>".substr($string, 0, $max)."<br><button onclick=\"showNext(this.parentNode)\">Next</button></div>";
$i=$max;
while ($test = substr($string, $i, $max))
{
$i+=$max;
echo "<div style=\"display:none\">".$test . "<br><button onclick=\"showPrev(this.parentNode)\">Prev</button>";
if ($i<strlen($string))
	echo "<button onclick=\"showNext(this.parentNode)\">Next</button>";
echo "</div>";
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.