我想获得这种想要的悬停图像效果吗?
我想知道是否有人知道代码?当您悬停图像时,它会移动。提前致谢。
// 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
看看这个 :) 你当然需要 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'});
}
);
}
);