我已经整理了一个小脚本(JavaScript - jQuery),用于测试依赖于 mousemove 事件的图像大小调整操作。简而言之,想法是单击图像一次然后拖动光标。每次鼠标移动时图像都会调整大小,其右下角会“跟随”光标。
我遇到的问题是:在你开始移动光标后,调整大小有点生涩。 1-2秒后,它运行非常顺利。如果您停止将光标移动一点然后再移动它,则会出现相同的情况。
此问题似乎只发生在谷歌浏览器中,所以我首先想到的是它与此浏览器的抗锯齿功能有关。但我不是专家。 图像非常大(宽度和高度 - 明智,而不是“KB” - )
您可以在此处测试此“迷你应用”:http://picselbocs.com/projects/helsinki-map-application/test.php
以下是代码:
<img src="Helsinki.jpg" id="map" style="width: 526px; height:300px; position: absolute; top:0; left:0" />
<script>
var drag = false;
(function(){
$('#map').on('click',function(){
drag = true;
});
$(document).on('mousemove',function(e){
if (drag)
$('#map').css({ 'height': e.pageY, 'width': e.pageX });
});
})();
</script>
如果有人能为这个问题提供解决方案,我将不胜感激。
答案 0 :(得分:0)
http://asp-net-by-parijat.blogspot.in/2014/09/aspnet-image-magnifying-effect-with.html !function($){ &#34;使用严格的&#34 ;;
var Magnify = function (element, options) {
this.init('magnify', element, options)
}
Magnify.prototype = {
constructor: Magnify
, init: function (type, element, options) {
var event = 'mousemove'
, eventOut = 'mouseleave';
this.type = type
this.$element = $(element)
this.options = this.getOptions(options)
this.nativeWidth = 0
this.nativeHeight = 0
if(!this.$element.parent().hasClass('magnify')) {
this.$element.wrap('<div class="magnify" \>');
this.$element.parent('.magnify').append('<div class="magnify-large" \>');
}
this.$element.siblings(".magnify-large").css("background","url('" + this.$element.attr("src") + "') no-repeat");
this.$element.parent('.magnify').on(event + '.' + this.type, $.proxy(this.check, this));
this.$element.parent('.magnify').on(eventOut + '.' + this.type, $.proxy(this.check, this));
}