jquery - how do I make next and previous buttons to manipulate div display? -
i need make presentation content of each page sits within div. html this:
<div id="p1" style="display:block;"> //content goes here <div id="nav"> <img class="imgswap" id="nextbtn"> </div> </div> <div id="p2" style="display:none;"> //content goes here <div id="nav"> <img class="imgswap" id="previousbtn"> <img class="imgswap" id="nextbtn"> </div> </div> <div id="p3" style="display:none;"> //content goes here <div id="nav"> <img class="imgswap" id="previousbtn"> </div> </div> when next button pressed, display of current div set none , display of next div set block. anywhere between 3 or 7 pages (the exact number not yet known) how formulate in jquery exactly? unsure of how name divs , address numbers in id. have jquery address click event:
$(function(){ $(".imgswap").mouseenter(function() { this.src = this.src.replace("_off", "_on"); }).mouseleave(function(){ this.src = this.src.replace("_on", "_off"); }).click(function() { alert("handler .click() called."); }); }); if seems silly way present information, because working within set, protected environment. can not use iframes this, instance, or presentation in powerpoint. appreciate take on this. thanks!
as can't have multiple elements same id, have change buttons id classes :
<img class="imgswap nextbtn"> <img class="imgswap previousbtn"> and doing same parents easier :
<div class="parent" style="display:block;"> and :
$(function(){ $(".imgswap").on({ mouseenter: function() { this.src = this.src.replace("_off", "_on"); }, mouseleave: function() { this.src = this.src.replace("_on", "_off"); }, click: function() { var direction = $(this).hasclass('nextbtn') ? 'next' : 'prev'; $(this).closest('.parent').hide() [direction]('.parent').show(); } }); }); this checks if button "next" or "previous" button, , changes jquery methods next() , prev() accordingly. hides current .parent , shows next/previous .parent. have figure out when there no more .parent elements show (hint: using length)
Comments
Post a Comment