答案 0 :(得分:4)
How do I view source of a webpage?
// Paralax Homepage Banner
jQuery("#banner").mousemove(
function(e){
/* Work out mouse position */
var offset = jQuery(this).offset();
var xPos = e.pageX - offset.left;
var yPos = e.pageY - offset.top;
/* Get percentage positions */
var mouseXPercent = Math.round(xPos / jQuery(this).width() * 100);
var mouseYPercent = Math.round(yPos / jQuery(this).height() * 100);
/* Position Each Layer */
jQuery(this).children('img').each(
function(){
var diffX = jQuery('#Parallax').width() - jQuery(this).width();
var diffY = jQuery('#Parallax').height() - jQuery(this).height();
var myX = diffX * (mouseXPercent / 1500); //) / 100) / 2;
var myY = diffY * (mouseYPercent / 1080);
var cssObj = {
'left': myX + 'px',
'top': myY + 'px'
}
//jQuery(this).css(cssObj);
jQuery(this).animate({left: myX, top: myY},{duration: 50, queue: false, easing: 'linear'});
}
);
}
);
http://www.colingrist.com/wp-content/themes/mill/scripts/functions.js
答案 1 :(得分:0)
看看这个:)你当然需要jquery库
jQuery("#banner").mousemove(
function(e){
/* Work out mouse position */
var offset = jQuery(this).offset();
var xPos = e.pageX - offset.left;
var yPos = e.pageY - offset.top;
/* Get percentage positions */
var mouseXPercent = Math.round(xPos / jQuery(this).width() * 100);
var mouseYPercent = Math.round(yPos / jQuery(this).height() * 100);
/* Position Each Layer */
jQuery(this).children('img').each(
function(){
var diffX = jQuery('#Parallax').width() - jQuery(this).width();
var diffY = jQuery('#Parallax').height() - jQuery(this).height();
var myX = diffX * (mouseXPercent / 1500); //) / 100) / 2;
var myY = diffY * (mouseYPercent / 1080);
var cssObj = {
'left': myX + 'px',
'top': myY + 'px'
}
//jQuery(this).css(cssObj);
jQuery(this).animate({left: myX, top: myY},{duration: 50, queue: false, easing: 'linear'});
}
);
}
);