Hi thanks for your help. I am using wordpress to run multiple jQuery functions. As soon as I add the second one it breaks the code on the first one. I can't figure out why this is.
<script type="text/javascript">
var timeInterval = null, transition_time = 0, time_between_slides = 4000;
jQuery(document).ready(function ($) {
/* This is for the slider */
var $slider = $('.slider');
var $sliderLi = $slider.find('li');
$sliderLi.hide();
//$slider.find('li:first').addClass('active').fadeIn(transition_time);
slideShow();
timeInterval = setInterval(slideShow, transition_time + time_between_slides);
function slideShow() {
var i = $slider.find('li.active').index();
$sliderLi.eq(i).removeClass('active').fadeOut(transition_time);
if (i == -1 || $sliderLi.length == i + 1) {
$slider.find('li:first').addClass('active').fadeIn(transition_time);
} else {
$sliderLi.eq(i + 1).addClass('active').fadeIn(transition_time);
}
};
$slider.mouseenter(function () {
clearInterval(timeInterval);
}).mouseleave(function () {
timeInterval = setInterval(slideShow, transition_time + time_between_slides);
});
});
</script>
Second Code
<script type="text/javascript">
jQuery(document).ready(function () {
var $popup = $('.popup');
$('area').on({
click : function(e){
var $this = $(this),
$obj = $('#'+$this.prop('alt'));
$popup.text($obj.text()).css({
top: e.pageY + 10,
left: e.pageX + 40,
}).show();
};
});
</script>
I have tried doing this two different ways. First was by plugging in the second code at the bottom of the first code. This ended up breaking the first code and the second code didn't work. I also tried splitting up as it is here. The second code still isn't working, even though it is working on http://jsfiddle.net/timlcooley/B5wa4/5/ I am not sure what is breaking the code. Any help in this process would be awesome.
Here is the edited code after reading everything people have shared. The problem still occurs. The slider breaks and the clickon area thing isn't working.
<script type="text/javascript">
var timeInterval = null, transition_time = 0, time_between_slides = 4000;
var $slider = $('.slider');
var $sliderLi = $slider.find('li');
var $popup = $('.popup');
jQuery(document).ready(function ($) {
/* This is for the slider */
$sliderLi.hide();
//$slider.find('li:first').addClass('active').fadeIn(transition_time);
slideShow();
timeInterval = setInterval(slideShow, transition_time + time_between_slides);
function slideShow() {
var i = $slider.find('li.active').index();
$sliderLi.eq(i).removeClass('active').fadeOut(transition_time);
if (i == -1 || $sliderLi.length == i + 1) {
$slider.find('li:first').addClass('active').fadeIn(transition_time);
} else {
$sliderLi.eq(i + 1).addClass('active').fadeIn(transition_time);
}
};
$slider.mouseenter(function () {
clearInterval(timeInterval);
}).mouseleave(function () {
timeInterval = setInterval(slideShow, transition_time + time_between_slides);
});
/* This is for the popup feature */
$('area').on({
click : function(e){
var $this = $(this),
$obj = $('#'+$this.prop('alt'));
$popup.text($obj.text()).css({
top: e.pageY + 10,
left: e.pageX + 40
}).show()
};
});
</script>
;(the 2nd to last one) run your code through a validator.document.ready()function call? Ideally, you would only want to call this once.<area>tag, for example?