www.91084.com

GVKun编程网logo

JS框架_(JQuery.js)网页文字评论弹幕(js实现评论功能)

9

在本文中,我们将为您详细介绍JS框架_(JQuery.js)网页文字评论弹幕的相关知识,并且为您解答关于js实现评论功能的疑问,此外,我们还会提供一些关于Google趋势中显示jQuery是最流行的J

在本文中,我们将为您详细介绍JS框架_(JQuery.js)网页文字评论弹幕的相关知识,并且为您解答关于js实现评论功能的疑问,此外,我们还会提供一些关于Google趋势中显示jQuery是最流行的JS框架、javascript – 如何使用JS或JQuery / JS框架通过所有浏览器选项卡发送信号(触发事件)?、jquery – 哪个HTML5 Media JS框架最好?、jquery 图片截取工具jquery.imagecropper.js_jquery的有用信息。

本文目录一览:

JS框架_(JQuery.js)网页文字评论弹幕(js实现评论功能)

JS框架_(JQuery.js)网页文字评论弹幕(js实现评论功能)

 

 

 百度云盘  传送门  密码:3azl

 

 

jQuery网页右下角文字评论弹幕效果

 

 

<!DOCTYPE html>
<html>
<head>
<title>jQuery网页右下角文字评论弹幕代码</title>
<meta charset="utf-8">
<meta id="scale" content="initial-scale=1, maximum-scale=1, user-scalable=0" name="viewport">

<script src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/data.js"></script>
<script type="text/javascript" src="js/index.js"></script>

<style type="text/css">
    *{
        padding:0;
        margin:0;
    }
    a{
        text-decoration: none;
    }

    p {
      position: fixed;
      top: 50%;
      left: 0;
      right: 0;
      text-align: center;
      transform: translateY(-50%);
      font-size: 40px;
      font-weight: 900;
      color: white;
      text-shadow: 0 0 50px black;
      text-transform: capitalize;
      font-family: ''Roboto'',''Helvetica'',''Arial'',sans-serif;
      letter-spacing: 5px;
    }

    .form-control{
        display: inline-block;
        width: auto;
        padding: 6px 12px;
        font-size: 14px;
        line-height: 1.42857143;
        color: #555;
        background-color: #fff;
        background-image: none;
        border: 1px solid #ccc;
        border-radius: 4px;
        -webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,.075);
        box-shadow: inset 0 1px 1px rgba(0,0,0,.075);
        -webkit-transition: border-color ease-in-out .15s,-webkit-box-shadow ease-in-out .15s;
        -o-transition: border-color ease-in-out .15s,box-shadow ease-in-out .15s;
        transition: border-color ease-in-out .15s,box-shadow ease-in-out .15s;
    }

    .btn{
        display: inline-block;
        padding: 6px 12px;
        margin-bottom: 0;
        font-size: 14px;
        font-weight: 400;
        line-height: 1.42857143;
        text-align: center;
        white-space: nowrap;
        vertical-align: middle;
        -ms-touch-action: manipulation;
        touch-action: manipulation;
        cursor: pointer;
        -webkit-user-select: none;
        -moz-user-select: none;
        -ms-user-select: none;
        user-select: none;
        background-image: none;
        border: 1px solid transparent;
        border-radius: 4px;
    }

    .btn-primary {
        color: #fff;
        background-color: #337ab7;
        border-color: #2e6da4;
    }

    /*组件主样式*/
    .overflow-text{
        display: block;
        white-space:nowrap;
        overflow:hidden; 
        text-overflow:ellipsis;
        opacity:0;
        clear: both;
        padding:3px 10px;
        border-radius: 10px;
        box-sizing: border-box;
        max-width: 100%;
        color:#fff;
        animation:colorchange 3s infinite alternate;
        -webkit-animation:colorchange 3s infinite alternate; /*Safari and Chrome*/
    }
    @keyframes colorchange{
        0%{
            color:red;
        }
        50%{
            color:green;
        }
        100%{
            color:#6993f9;
        }
    }
    
</style>

</head>
<body>

<p>Gary</p>

<center><br><br><br>
<button id="stop" class="btn btn-primary">停止</button>
<button id="open" class="btn btn-primary"></button>
<input type="text" class="form-control" name="" id="barrage_content" placeholder="添加弹幕内容"><button class="btn btn-primary" id="submit_barraget">发送</button>
</center>

<script type="text/javascript">

// 数据初始化
var Obj = $(''body'').barrage({
    data : data, //数据列表
    row : 5,   //显示行数
    time : 1000, //间隔时间
    gap : 20,    //每一个的间隙
    position : ''fixed'', //绝对定位
    direction : ''bottom right'', //方向
    ismoseoverclose : true, //悬浮是否停止
})
Obj.start(); 

//添加评论
$("#submit_barraget").click(function(){

    var val = $("#barrage_content").val();
    //此格式与dataa.js的数据格式必须一致
    var addVal = {
        href : '''',
        text : val
    }
    //添加进数组
    Obj.data.unshift(addVal);
    alert(''评论成功'');

})

$("#open").click(function(){
    Obj.start(); 
})
$("#stop").click(function(){
    Obj.close();
})
</script>

</body>
</html>
index.html

 

    $.fn.barrage = function(opt){

        var _self = $(this);

        var opts = {   //默认参数
            data : [], //数据列表
            row : 5,   //显示行数
            time : 2000, //间隔时间
            gap : 20,    //每一个的间隙
            position : ''fixed'', //绝对定位
            direction : ''bottom right'', //方向
            ismoseoverclose : true, //悬浮是否停止
        }

        var settings = $.extend({},opts,opt); //合并参数
        var M = {},Obj = {}; 
        Obj.data = settings.data;
        M.vertical = settings.direction.split(/\s+/)[0]; //纵向
        M.horizontal = settings.direction.split(/\s+/)[1]; //横向
        M.bgColors = [''#edbccc'',''#edbce7'',''#c092e4'',''#9b92e4'',''#92bae4'',''#92d9e4'',''#92e4bc'',''#a9e492'',''#d9e492'',''#e4c892'']; //随机背景色数组
        Obj.arrEle = []; //预计存储dom集合数组
        M.barrageBox = $(''<div id="barrage" style="z-index:999;max-width:100%;position:''+settings.position+'';''+M.vertical+'':0;''+M.horizontal+'':0;"></div>''); //存所有弹幕的盒子
        M.timer = null; 
        var createView = function(){
            var randomIndex = Math.floor(Math.random() * M.bgColors.length);
            var ele = $(''<a class="overflow-text" target="_blank" style="opacity:0;text-align:''+settings.direction.split(/\s+/)[1]+'';float:''+settings.direction.split(/\s+/)[1]+'';background-color:''+M.bgColors[randomIndex]+''"; href="''+(Obj.data[0].href ? Obj.data[0].href : "javascript:;")+''">''+Obj.data[0].text+''</a>'');
            var str = Obj.data.shift();
            if(M.vertical  == ''top''){
                ele.animate({
                    ''opacity'' : 1,
                    ''margin-top'' : settings.gap,
                },1000)
                M.barrageBox.prepend(ele);
            }else{
                ele.animate({
                    ''opacity'' : 1,
                    ''margin-bottom'' : settings.gap,
                },1000)
                M.barrageBox.append(ele);
            }
            Obj.data.push(str);

            if(M.barrageBox.children().length > settings.row){

                M.barrageBox.children().eq(0).animate({
                    ''opacity'' : 0,
                },300,function(){
                    $(this).css({
                        ''margin'' : 0,
                    }).remove();
                })
            }
        }
        M.mouseClose = function(){
            settings.ismoseoverclose && (function(){

                M.barrageBox.mouseover(function(){
                    clearInterval(M.timer);
                    M.timer = null;
                }).mouseout(function(){
                    M.timer = setInterval(function(){ //循环
                        createView();
                    },settings.time)
                })

            })()
        }
        Obj.close = function(){
            M.barrageBox.remove();
            clearInterval(M.timer);
            M.timer = null;
        }
        Obj.start = function(){
            if(M.timer) return;
            _self.append(M.barrageBox); //把弹幕盒子放到页面中
            createView(); //创建试图并开始动画
            M.timer = setInterval(function(){ //循环
                createView();
            },settings.time)
            M.mouseClose();
        }
        
        return Obj;
    }
index.js

 

var data = [
    {href : ''http://www.baidu.com'',text : ''百度''},
    {href : ''http://www.cnblogs.com/1138720556Gary/'',text : ''Cynical丶Gary''},
    {href : '''',text : ''这是弹幕_1''},
    {href : '''',text : ''这是弹幕_2''},
    {href : '''',text : ''这是弹幕_3''}
]
data.js

 

 

实现过程:

 

CSS

 

弹幕文字动画效果

    @keyframes colorchange{
        0%{
            color:red;
        }
        50%{
            color:green;
        }
        100%{
            color:#6993f9;
        }
    }

通过 @keyframes 规则,能够创建随着弹幕出现时间改变弹幕颜色动画

  0% 是动画的开始时间,100% 动画的结束时间

 

初始化弹幕

var data = [
    {href : ''http://www.baidu.com'',text : ''百度''},
    {href : ''http://www.cnblogs.com/1138720556Gary/'',text : ''Cynical丶Gary''},
    {href : '''',text : ''这是弹幕_1''},
    {href : '''',text : ''这是弹幕_2''},
    {href : '''',text : ''这是弹幕_3''}
]

href作为参数链接,新建弹幕默认无链接

 

弹幕属性

        var opts = {   //默认参数
            data : [], //数据列表
            row : 5,   //显示行数
            time : 2000, //间隔时间
            gap : 20,    //每一个的间隙
            position : ''fixed'', //绝对定位
            direction : ''bottom right'', //方向
            ismoseoverclose : true, //悬浮是否停止
        }

 

 

随机背景色数组

M.bgColors = [''#edbccc'',''#edbce7'',''#c092e4'',''#9b92e4'',''#92bae4'',''#92d9e4'',''#92e4bc'',''#a9e492'',''#d9e492'',''#e4c892''];

 

 

弹幕展示效果

        var createView = function(){
            var randomIndex = Math.floor(Math.random() * M.bgColors.length);
            var ele = $(''<a class="overflow-text" target="_blank" style="opacity:0;text-align:''+settings.direction.split(/\s+/)[1]+'';float:''+settings.direction.split(/\s+/)[1]+'';background-color:''+M.bgColors[randomIndex]+''"; href="''+(Obj.data[0].href ? Obj.data[0].href : "javascript:;")+''">''+Obj.data[0].text+''</a>'');
            var str = Obj.data.shift();
            if(M.vertical  == ''top''){
                ele.animate({
                    ''opacity'' : 1,
                    ''margin-top'' : settings.gap,
                },1000)
                M.barrageBox.prepend(ele);
            }else{
                ele.animate({
                    ''opacity'' : 1,
                    ''margin-bottom'' : settings.gap,
                },1000)
                M.barrageBox.append(ele);
            }
            Obj.data.push(str);

            if(M.barrageBox.children().length > settings.row){

                M.barrageBox.children().eq(0).animate({
                    ''opacity'' : 0,
                },300,function(){
                    $(this).css({
                        ''margin'' : 0,
                    }).remove();
                })
            }
        }
        

prepend():在被选元素的开头(仍位于内部)插入指定内容

animate() :执行 CSS 属性集的自定义动画

shift() 方法:用于把数组的第一个元素从其中删除,并返回第一个元素的值

 

当需要暂时的弹幕数量>最大展示数量(这里是5),那么全部展现出来,否则通过opacity()方法,改变弹幕透明度

 

语法

 

鼠标放置弹幕上,弹幕停止滚动

        M.mouseClose = function(){
            settings.ismoseoverclose && (function(){

                M.barrageBox.mouseover(function(){
                    clearInterval(M.timer);
                    M.timer = null;
                }).mouseout(function(){
                    M.timer = setInterval(function(){ //循环
                        createView();
                    },settings.time)
                })

            })()
        }

 通过.ismoseoverclose判断鼠标是否悬停在弹幕上

  M.timer = null使弹幕停止滚动

 

关闭弹幕

        Obj.close = function(){
            M.barrageBox.remove();
            clearInterval(M.timer);
            M.timer = null;
        }
        

 

开启弹幕

        Obj.start = function(){
            if(M.timer) return;
            _self.append(M.barrageBox); //把弹幕盒子放到页面中
            createView(); //创建试图并开始动画
            M.timer = setInterval(function(){ //循环
                createView();
            },settings.time)
            M.mouseClose();
        }

 

 

DOM

 

<script type="text/javascript">

// 数据初始化
var Obj = $(''body'').barrage({
    data : data, //数据列表
    row : 5,   //显示行数
    time : 1000, //间隔时间
    gap : 20,    //每一个的间隙
    position : ''fixed'', //绝对定位
    direction : ''bottom right'', //方向
    ismoseoverclose : true, //悬浮是否停止
})
Obj.start(); 

//添加评论
$("#submit_barraget").click(function(){

    var val = $("#barrage_content").val();
    //此格式与dataa.js的数据格式必须一致
    var addVal = {
        href : '''',
        text : val
    }
    //添加进数组
    Obj.data.unshift(addVal);
    alert(''评论成功'');

})

$("#open").click(function(){
    Obj.start(); 
})
$("#stop").click(function(){
    Obj.close();
})
</script>

 

Google趋势中显示jQuery是最流行的JS框架

Google趋势中显示jQuery是最流行的JS框架

编译:GBin1.com

以下是2004到2011年各大流行JS框架主站的访问量趋势图!

jQuery很明显是最流行的框架!顺便说一句,过去很难和prototype比较,因为它过去非常流行的词儿,我这里用prototype js来在google里进行搜索

流行趋势比较

同时我们也可以从流行趋势里比较: JS框架比较或者jQuery最近趋势。

如何计算的

你可能注意到了不同搜索的Y轴变化量。数据是如何绘制的呢?

你在Y轴看到搜索量标示不是绝对的搜索流量,实际趋势计算在选择时间段1.0时你输入的第一个短语的平均搜索流量。以后的短语则相对于第一个来衡量。注意所有的数值都是相对于流量来说的。

原文来自: GBin1分享:Google趋势中显示jQuery是最流行的JS框架

javascript – 如何使用JS或JQuery / JS框架通过所有浏览器选项卡发送信号(触发事件)?

javascript – 如何使用JS或JQuery / JS框架通过所有浏览器选项卡发送信号(触发事件)?

我在浏览器中有很多打开的网站标签.我如何通过所有这些发送信号(触发事件),也许有人知道关于那个的好文章/博客?示例:在一个选项卡中,我将登录该站点,几秒钟后,必须更改其他选项卡中的用户界面.执行此案例的最佳做法是什么建议?
对不起英语不好,我不是母语.

最佳答案
您可以使用浏览器中的数据存储localStorage,该数据存储在查看同一域的所有选项卡/窗口中共享.当任何选项卡进行存储更改时,会在所有选项卡中触发存储事件.这里有一个演示:http://html5demos.com/storage-events

jquery – 哪个HTML5 Media JS框架最好?

jquery – 哪个HTML5 Media JS框架最好?

我想使用 jquery自定义视频播放器以获得额外的按钮和控件.我发现两个看起来像是可行的候选人,我有兴趣听到哪个更好(或者还有另一个最好的).请记住,我的目标是修改它(不只是删除和播放).

以下是我到目前为止找到的两位候选人:

> http://videojs.com/
> http://mediaelementjs.com/

解决方法

在阅读了有关Framework的详细信息后,我投票支持 http://mediaelementjs.com/.它有比VideoJS更多的配置选项.

jquery 图片截取工具jquery.imagecropper.js_jquery

jquery 图片截取工具jquery.imagecropper.js_jquery

除了jquery,本插件还引用了UI库,包括ui.draggable.js
ImageCropper 演示需要asp.net支持。测试通过
ImageCropper 下载 http://www.jb51.net/jiaoben/25688.html
插件用法:

复制代码 代码如下:

var imageCropper = $(''#imgBackground'').imageCropper();

要注意的是此插件只应用在有src属性的img标签上。
通过插件输出的参数,即可以通过服务器端代码截取图片,比如:
复制代码 代码如下:

$(''#imgCroppedImage'').attr(''src'', ''CropImage.ashx?p='' + imageCropper.settings.imagePath + ''&z='' + imageCropper.settings.zoomLevel + ''&t='' + imageCropper.settings.top + ''&l='' + imageCropper.settings.left + ''&w='' + imageCropper.settings.width + ''&h='' + imageCropper.settings.height + ''&'' + Math.random());

asp.net hander CropImage.ashx:
复制代码 代码如下:

public class CropImage : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
string imgPath = Convert.ToString(context.Request["p"]);
float zoomLevel = Convert.ToSingle(context.Request["z"]);
int top = Convert.ToInt32(context.Request["t"]);
int left = Convert.ToInt32(context.Request["l"]);
int width = Convert.ToInt32(context.Request["w"]);
int height = Convert.ToInt32(context.Request["h"]);
context.Response.ContentType = "image/jpeg";
Crop(HttpContext.Current.Server.MapPath(imgPath), zoomLevel, top, left, width, height).WriteTo(context.Response.OutputStream);
}
public MemoryStream Crop(string imgPath, float zoomLevel, int top, int left, int width, int height)
{
Image img = Image.FromFile(imgPath);
Bitmap bitmap = new Bitmap(width, height);
Graphics g = Graphics.FromImage(bitmap);
g.DrawImage(img, new Rectangle(0, 0, width, height), new Rectangle((int)(left / zoomLevel), (int)(top / zoomLevel), (int)(width / zoomLevel), (int)(height / zoomLevel)), GraphicsUnit.Pixel);
MemoryStream ms = new MemoryStream();
bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
img.Dispose();
g.Dispose();
bitmap.Dispose();
return ms;
}
public bool IsReusable
{
get
{
return false;
}
}
}

重点是插件,因为源代码注释比较全,直接贴代码在这:
复制代码 代码如下:

/**
* Copyright (c) 2010 Viewercq (http://www.cnblogs.com/viewercq/archive/2010/04/04/1704093.html)
* Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
* and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
*
* Version: 1.0
*
* Demo: https://dl.dropbox.com/u/4390741/ImageCropper.htm
*/
; (function($) {
$.fn.extend({
imageCropper: function(options) {
if (!this.is(''img'') || typeof this.attr(''src'') == ''undefined'' || this.attr(''src'') == '''') {
throw ''Please notice that this jquery plguin only could be applied to img and the src of img could not be null!'';
}
var defaults = {
//原图路径
imagePath: this.attr(''src''),
//缩放级别
zoomLevel: 1,
//图片相对于截取框是否居中
center: false,
//截取框与图片的相对位置
left: 0, top: 0,
//截取框的大小
width: 200, height: 200,
//工作区大小
cropWorkAreaSize: { width: 600, height: 400 },
//截取框相对于工作区的位置
cropFrameRect: { center: true, top: 0, left: 0 },
//缩放范围
zoom: { min: 0, max: 2, step: 0.01 },
//回调函数
callbacks: {
//移动图片后
dragging: false,
//缩放后
zoomed: false
}
};
if (options) {
defaults = $.extend(defaults, options);
}
return new imageCropper(this, defaults);
}
});
function imageCropper(image, settings) {
this.init(image, settings);
};
imageCropper.prototype = {
settings: false,
wrapper: $(''
''),
zoomWrapper: $(''
''),
img: false,
init: function(image, settings) {
var context = this;
this.settings = settings;
image.addClass(''background-img'');
//生成html
image.wrap(this.wrapper).wrap(''
'').wrap(''
'');
this.wrapper = $(''.image-cropper-wrapper'');
$(''.crop-work-area'', this.wrapper).append(''
'');
this.wrapper.append(this.zoomWrapper);
$(''.image-cropper-wrapper'', this.wrapper).disableSelection();
this.reset();
//图片的拖动
$(''.crop-background'', this.wrapper).draggable({
containment: $(''.drag-containment'', this.wrapper),
cursor: ''move'',
drag: function(event, ui) {
var self = $(this).data(''draggable'');
//同时移动前景图
$(''.foreground-img'', this.wrapper).css({
left: (parseInt(self.position.left) - context.settings.cropFrameRect.left - 1) + ''px'',
top: (parseInt(self.position.top) - context.settings.cropFrameRect.top - 1) + ''px''
});
//得到截图左上点坐标
context.settings.left = context.settings.cropFrameRect.left - parseInt($(this).css(''left''));
context.settings.top = context.settings.cropFrameRect.top - parseInt($(this).css(''top''));
//移动图片的callback
context.fireCallback(context.settings.callbacks.dragging);
}
});
$(''.foreground-img'', this.wrapper).draggable({
containment: $(''.drag-containment'', this.wrapper),
cursor: ''move'',
drag: function(event, ui) {
var self = $(this).data(''draggable'');
//同时移动背景
$(''.crop-background'', this.wrapper).css({
left: (parseInt(self.position.left) + context.settings.cropFrameRect.left + 1) + ''px'',
top: (parseInt(self.position.top) + context.settings.cropFrameRect.top + 1) + ''px''
});
//得到截图左上点坐标
context.settings.left = context.settings.cropFrameRect.left - parseInt($(''.crop-background'', this.wrapper).css(''left''));
context.settings.top = context.settings.cropFrameRect.top - parseInt($(''.crop-background'', this.wrapper).css(''top''));
//移动图片的callback
context.fireCallback(context.settings.callbacks.dragging);
}
});
//点击缩放
$(''.zoom-out-button,.zoom-in-button'', this.wrapper).click(function() {
var step = $(this).hasClass(''zoom-in-button'') ? context.settings.zoom.step : -context.settings.zoom.step;
var tempZoomLevel = context.formatNumber(context.settings.zoomLevel + step, 3);
//如果缩放级别超出范围 或者 缩放导致图片右下角没在截取框内 则取消缩放
if (context.settings.zoomLevel >= context.settings.zoom.min
&& context.settings.zoomLevel && parseInt($(''.crop-background'', this.wrapper).css(''left'')) + tempZoomLevel * context.img.width > context.settings.cropFrameRect.left + context.settings.width
&& parseInt($(''.crop-background'', this.wrapper).css(''top'')) + tempZoomLevel * context.img.height > context.settings.cropFrameRect.top + context.settings.height
) {
context.settings.zoomLevel = tempZoomLevel;
context.zoom(context.img.width * context.settings.zoomLevel, context.img.height * context.settings.zoomLevel);
$(''.zoom-scroller'', this.wrapper).css(''left'', context.settings.zoomLevel * 200 / (context.settings.zoom.max - context.settings.zoom.min) + ''px'');
}
context.fireCallback(context.settings.callbacks.zoomed);
});
//滚动条缩放
var cancelZoomScroll = false;
$(''.zoom-scroller'', this.wrapper).draggable({
containment: $(''.zoom-scrollbar'', this.wrapper),
axis: ''x'',
drag: function(event, ui) {
var tempZoomLevel = (context.settings.zoom.max - context.settings.zoom.min) * parseInt($(this).css(''left'')) / 200;
//如果缩放级别超出范围 或者 缩放导致图片右下角没在截取框内 则取消缩放
if (parseInt($(''.crop-background'', this.wrapper).css(''left'')) + tempZoomLevel * context.img.width > context.settings.cropFrameRect.left + context.settings.width
&& parseInt($(''.crop-background'', this.wrapper).css(''top'')) + tempZoomLevel * context.img.height > context.settings.cropFrameRect.top + context.settings.height
) {
context.settings.zoomLevel = tempZoomLevel;
context.zoom(context.img.width * context.settings.zoomLevel, context.img.height * context.settings.zoomLevel);
cancelZoomScroll = false;
context.fireCallback(context.settings.callbacks.zoomed);
}
else {
cancelZoomScroll = true;
}
},
stop: function(event, ui) {
//如果缩放级别无效 则重置滚动条的值
if (cancelZoomScroll) {
$(''.zoom-scroller'', this.wrapper).css(''left'', context.settings.zoomLevel * 200 / (context.settings.zoom.max - context.settings.zoom.min) + ''px'');
}
}
});
},
reset: function() {
this.img = new Image();
this.img.src = this.settings.imagePath;
//截取框大于工作区,则放大工作区
var tempSize = {
width: Math.max(this.settings.cropWorkAreaSize.width, this.settings.width),
height: Math.max(this.settings.cropWorkAreaSize.height, this.settings.height)
};
//如果截取框在工作区中居中,则重新设置截取框的位置
if (this.settings.cropFrameRect.center) {
this.settings.cropFrameRect.left = (tempSize.width - this.settings.width) / 2;
this.settings.cropFrameRect.top = (tempSize.height - this.settings.height) / 2;
}
//如果截取框在图片中居中,则重新设置图片与截取框的相对位置
if (this.settings.center) {
this.settings.left = (this.img.width * this.settings.zoomLevel - this.settings.width) / 2;
this.settings.top = (this.img.height * this.settings.zoomLevel - this.settings.height) / 2;
}
this.wrapper.width(tempSize.width + 2).height(tempSize.height + 25);
$(''.foreground-img,.background-img'', this.wrapper).attr(''src'', this.settings.imagePath);
$(''.crop-work-area'', this.wrapper).width(tempSize.width).height(tempSize.height);
$(''.crop-frame'', this.wrapper).css({
left: this.settings.cropFrameRect.left + ''px'',
top: this.settings.cropFrameRect.top + ''px'',
width: this.settings.width + ''px'',
height: this.settings.height + ''px''
});
$(''.foreground-img'', this.wrapper).css({
left: (-this.settings.cropFrameRect.left - 1) + ''px'',
top: (-this.settings.cropFrameRect.top - 1) + ''px''
});
$(''.zoom-scroller'', this.wrapper).css(''left'', this.settings.zoomLevel * 200 / (this.settings.zoom.max - this.settings.zoom.min) + ''px'');
$(''.crop-background'', this.wrapper).css({
opacity: 0.3,
left: this.settings.cropFrameRect.left - this.settings.left + ''px'',
top: this.settings.cropFrameRect.top - this.settings.top + ''px''
});
$(''.foreground-img'', this.wrapper).css({
left: -this.settings.left + ''px'',
top: -this.settings.top + ''px''
});
this.settings.left = this.settings.cropFrameRect.left - parseInt($(''.crop-background'', this.wrapper).css(''left''));
this.settings.top = this.settings.cropFrameRect.top - parseInt($(''.crop-background'', this.wrapper).css(''top''));
this.zoom(this.img.width * this.settings.zoomLevel, this.img.height * this.settings.zoomLevel);
},
zoom: function(width, height) {
$(''.crop-background, .background-img, .foreground-img'', this.wrapper).width(width).height(height);
//调整拖动限制框
$(''.drag-containment'', this.wrapper).css({
left: this.settings.cropFrameRect.left + this.settings.width - this.settings.zoomLevel * this.img.width + 1 + ''px'',
top: this.settings.cropFrameRect.top + this.settings.height - this.settings.zoomLevel * this.img.height + 1 + ''px'',
width: 2 * this.settings.zoomLevel * this.img.width - this.settings.width + ''px'',
height: 2 * this.settings.zoomLevel * this.img.height - this.settings.height + ''px''
});
},
formatNumber: function(number, bit) {
return Math.round(number * Math.pow(10, bit)) / Math.pow(10, bit);
},
fireCallback: function(fn) {
if ($.isFunction(fn)) {
fn.call(this);
};
}
};
})(jQuery);

关于JS框架_(JQuery.js)网页文字评论弹幕js实现评论功能的问题我们已经讲解完毕,感谢您的阅读,如果还想了解更多关于Google趋势中显示jQuery是最流行的JS框架、javascript – 如何使用JS或JQuery / JS框架通过所有浏览器选项卡发送信号(触发事件)?、jquery – 哪个HTML5 Media JS框架最好?、jquery 图片截取工具jquery.imagecropper.js_jquery等相关内容,可以在本站寻找。

本文标签:

上一篇电脑怎么设置创建wifi(电脑怎么设置创建的新文件夹日竖版的)

下一篇JS 中深拷贝的几种实现方法(js 中深拷贝的几种实现方法是什么)