I am using timer to navigate divs with help of <a href="#id">.At present if the users click div3 if timer shows div1 it goes to div2.but my requirement is if the users clicks div3 from div1 it has show div3 and move to div4 .can
any one help what is wrong or am i missing something?
To Show/Hide div based on href id
=======================================
$(function () {
$("a.menu").click(function () {
$("div.featuredposts_content").hide();
$($(this).attr('href')).show();
return false;
});
});
To change div for given period of time(ex 15 secs)
===========================================
$(function () {
var counter = 0,
divs = $('#cat1, #cat2, #cat3,#cat4');
function showDiv() {
divs.hide() // hide all divs
.filter(function (index) { return index == counter % 4; }) // figure out correct div to show
.show('fast'); // and show it
counter++;
}; // function to loop through divs and show correct div
showDiv(); // show first div
setInterval(function () {
showDiv(); // show next div
}, 15 * 1000); // do this every 10 seconds
});
ram07
Member
1 Points
21 Posts
jquery timer doesnt show specific div that is clicked instead it navigates to div based on timer
Dec 22, 2012 07:31 AM|LINK
I am using timer to navigate divs with help of <a href="#id">.At present if the users click div3 if timer shows div1 it goes to div2.but my requirement is if the users clicks div3 from div1 it has show div3 and move to div4 .can any one help what is wrong or am i missing something?
To Show/Hide div based on href id ======================================= $(function () { $("a.menu").click(function () { $("div.featuredposts_content").hide(); $($(this).attr('href')).show(); return false; }); }); To change div for given period of time(ex 15 secs) =========================================== $(function () { var counter = 0, divs = $('#cat1, #cat2, #cat3,#cat4'); function showDiv() { divs.hide() // hide all divs .filter(function (index) { return index == counter % 4; }) // figure out correct div to show .show('fast'); // and show it counter++; }; // function to loop through divs and show correct div showDiv(); // show first div setInterval(function () { showDiv(); // show next div }, 15 * 1000); // do this every 10 seconds });urenjoy
Star
12139 Points
1818 Posts
Re: jquery timer doesnt show specific div that is clicked instead it navigates to div based on ti...
Dec 22, 2012 07:53 AM|LINK
You have to set counter value on div click. try something like following on click
counter = divs.index($(this));
ram07
Member
1 Points
21 Posts
Re: jquery timer doesnt show specific div that is clicked instead it navigates to div based on ti...
Dec 22, 2012 08:04 AM|LINK
where should i write this code exactly