Hi,
I have a website on which i want to run two pieces of Jquery, the problem is whilst both work fine individually once they are placed together they stop working, and i think it must be because they conflict as they both call the same function.
below are the two individual pieces of javascript.
and the second peice of code:Code://avoid conflict with other script $j=jQuery.noConflict(); $j(document).ready(function($) { //this is the floating content var $floatingbox = $('#floating-box'); if($('#body').length > 0){ var bodyY = parseInt($('#body').offset().top) - 20; var originalX = $floatingbox.css('margin-left'); $(window).scroll(function () { var scrollY = $(window).scrollTop(); var isfixed = $floatingbox.css('position') == 'fixed'; if($floatingbox.length > 0){ $floatingbox.html("srollY : " + scrollY + ", bodyY : " + bodyY + ", isfixed : " + isfixed); if ( scrollY > bodyY && !isfixed ) { $floatingbox.stop().css({ position: 'fixed', left: '50%', top: 20, marginLeft: -500 }); } else if ( scrollY < bodyY && isfixed ) { $floatingbox.css({ position: 'relative', left: 0, top: 0, marginLeft: originalX }); } } }); } });
Now when these two items of code are on the same page they just simply stop working. I am fairly new to javascript and so do not have a great amount of experience but i was wondering if it was related to the fact that both use ready function. If so is there away around this?.Code:$(document).ready(function(){ $(".toggle_container").hide(); $("h2.expand_heading").toggle(function(){ $(this).addClass("active"); }, function () { $(this).removeClass("active"); }); $("h2.expand_heading").click(function(){ $(this).next(".toggle_container").slideToggle("slow"); }); $(".expand_all").toggle(function(){ $(this).addClass("expanded"); }, function () { $(this).removeClass("expanded"); }); $(".expand_all").click(function(){ $(".toggle_container").slideToggle("slow"); }); });
Any suggestions would be greatfully appreciated.
Thanks
Lee


Reply With Quote

Bookmarks