亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

對于.replaceWith() .call(this) 在實際效果中的不解。

對于.replaceWith() .call(this) 在實際效果中的不解。

慕移動2735134 2019-02-12 12:33:55
從網上下載的一個jquery文字特效代碼,有兩處不懂的,請大神教一下。效果顯示jQuery基于CSS3文字動畫特效html文件中有<p?class="ex1">TEXTYLE</p> <p?class="ex2">FLIP</p>js文件中 (function($){?? ?$.fn.textyleF?=?function(options){ ???var?target?=?this; ???var?targetTxt?=?target.contents(); ???var?defaults?=?{ ?????duration?:?1000, ?????delay?:?150, ?????easing?:?'ease', ?????callback?:?null ???}; ???var?setting?=?$.extend(defaults,?options); ???targetTxt.each(function(){ ?????var?texts?=?$(this); ?????if(this.nodeType?===?3){ ???????mkspn(texts); ?????} ???}); ???function?mkspn(texts){ ?????texts.replaceWith(texts.text().replace(/(\S)/g,'<span>$1</span>')); ?????console.log("texts="+texts); ???} ???return?this.each(function(i){ ?????var?child?=?target.children('span'); ?????target.css('opacity',1); ?????child.each(function(i){ ???????$(this).delay(setting.delay*i) ?????????.queue(function(next)?{ ?????????$(this).css({ ???????????display?:?'inline-block', ???????????transform?:?'rotateY(0deg)?rotateX(0deg)', ???????????opacity?:?1, ???????????transitionDuration?:?setting.duration?+?'ms', ???????????transitionTimingFunction?:?setting.easing ?????????}) ?????????next(); ???????}); ???????if(typeof?setting.callback?===?'function'){ ?????????$(this).on('transitionend',?function()?{ ?????????? ???????????setting.callback.call(this); ??????????? ?????????}); ???????}?else?{ ?????????console.error('Textyle.js:?`setting.callback`?must?be?a?function.'); ???????} ?????}); ???}); ?}; }(?jQuery?)); $(window).on('load',function(){ ??$('.ex1').textyleF(); ??$('.ex2').textyleF({ ??????duration?:?2000, ??????delay?:?200, ??????easing?:?'cubic-bezier(0.77,?0,?0.175,?1)', ??????callback?:?function(){ ????????$(this).css({ ??????????color?:?'#fff', ??????????transition?:?'1s', ????????}); ????????$('.desc').css('opacity',1); ??????} ????}); ??});問題1: texts.replaceWith(texts.text().replace(/(\S)/g,'<span>$1</span>'));????外層的replaceWith()的作用是把括號里的內容替換texts的文本對么?????但是控制臺打印texts,不是<span>T</span>這樣的,是Object [ #text ]?問題2:setting.callback.call(this);?? 1、 我對call和this的用法一直沒搞懂,這里要實現的效果應該是調用$('.ex2')..textyleF()里設置的callback吧???? 2、那.call(this);在這里作用是什么?前后的this都是HTMLSpanElement。??? 3、call()可以改變this的指向?但是在這之前打印this是 。<span?style="display:?inline-block;?t…ier(0.77,?0,?0.175,?1);"> <span?style="display:?inline-block;?t…or:?rgb(255,?255,?255);"> <span?style="display:?inline-block;?t…ier(0.77,?0,?0.175,?1);"> <span?style="display:?inline-block;?t…or:?rgb(255,?255,?255);"> <span?style="display:?inline-block;?t…ier(0.77,?0,?0.175,?1);"> <span?style="display:?inline-block;?t…or:?rgb(255,?255,?255);"> <span?style="display:?inline-block;?t…ier(0.77,?0,?0.175,?1);"> <span?style="display:?inline-block;?t…or:?rgb(255,?255,?255);"> <span?style="display:?inline-block;?t…or:?rgb(255,?255,?255);"> <span?style="display:?inline-block;?t…or:?rgb(255,?255,?255);"> <span?style="display:?inline-block;?t…or:?rgb(255,?255,?255);"> <span?style="display:?inline-block;?t…or:?rgb(255,?255,?255);">?在此句之后打印this,就沒有<span style="display: inline-block; t…ier(0.77, 0, 0.175, 1);">所以調用了.call(this)的作用是什么?this指向變了?問題3:①window.onload == $(window).on('load') ???????????? ② $(function($){});== $(document).ready()? ???????????? ③ ②在dom樹加載完就執行,所以是在①之前執行??????????? ④ (function($){...})(jquery);是自執行匿名函數?也是在dom加載完運行,那和$(function($){});有區別?
查看完整描述

2 回答

  • 2 回答
  • 0 關注
  • 1247 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號