开发者

Jquery and Regular Javascript Interference [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 12 years ago.

Im building a site in joomla and I recently purchased a content slider for it that is built in plain old Javascript, then I built some content boxes that have an animation on them provided by Jquery. Right now the animations work, but the开发者_开发技巧 slider doesn't. I was wondering how I could get the page to work using both. Here's my code

 <script src="http://code.jquery.com/jquery-1.4.4.js"></script>
<script>jQuery.noConflict();
$(document).ready(function() { 
  //settings 
  var opacity = 0.5, toOpacity = 1, duration = 350; 
  //set opacity ASAP and events 
  $('.opacity').css('opacity',opacity).hover(function() { 
      $(this).fadeTo(duration,toOpacity); 
    }, function() { 
      $(this).fadeTo(duration,opacity); 
    } 
  ); 
});
</script>


Try calling this after the libraries are loaded:

jQuery.noConflict();

Also, try replacing your jQuery ready function with this:

jQuery(document).ready(function($){

This passes the $ shortcut into the jQuery code block, but should still avoid conflicts outside it.

You can read up on the subject here in the jQuery docs.


Have you checked for potential conficts that may have occurred ($'s in the code)? You can run your jquery script in no conflict mode to fix that

http://api.jquery.com/jQuery.noConflict/


According to the jQuery docs on jQuery.noConflict...

Description: Relinquish jQuery's control of the $ variable.

So that means that after you call it, you must use jQuery instead of $ for jQuery calls.

For example, change $(document).ready(function() { ... }); to jQuery(document).ready(function() { ... });.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜