开发者

Convert jQuery to Prototype (small code)? [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not general开发者_Go百科ly applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 11 years ago.

I have a site that runs n Vivvo CMS. It is based mainly on Prototype. I would like to implement on site this function, but is jQuery based. Allthough i use jQuery.noconflict, it still doesn't run.

I would like to convert the code below from jQuery to Prototype, can anyone help me?

$(document).ready(function(){
 $(window).scroll(function(){
  // get the height of #wrap
  var h = $('#wrap').height();
  var y = $(window).scrollTop();
  if( y > (h*.25) && y < (h*.75) ){
   // if we are show keyboardTips
   $("#tips").fadeIn("slow");
  } else {
   $('#tips').fadeOut('slow');
  }
 });
});

Thank you.


You certainly can use jQuery. instead of $. but it's an awful lot of extra typing ( :) ).

In the rare situations where I have to mix Prototype and jQuery, I prefer to handle it like this.

Put jQuery in noConflict mode

<script>jQuery.noConflict()</script>

Then wrap your jQuery code in this:

(function($) {

    //Now I can do jQuery stuff and use the $
    $(document).ready( function() {

    });

})(jQuery)

What you're doing is creating an anonymous function that calls itself and you're passing the jQuery object to the function as an argument.

The beauty is that everything inside the function is local only to that function so you don't have to worry about the $ inside the function stomping all over Prototype and you don't have to suffer the pain of converting jQuery code to Prototype.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜