Convert jQuery to Prototype (small code)? [closed]
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.
精彩评论