從網(wǎng)上下載的一個(gè)jquery文字特效代碼,有兩處不懂的,請(qǐng)大神教一下。效果顯示jQuery基于CSS3文字動(dòng)畫特效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);
??????}
????});
??});問(wèn)題1: texts.replaceWith(texts.text().replace(/(\S)/g,'<span>$1</span>'));????外層的replaceWith()的作用是把括號(hào)里的內(nèi)容替換texts的文本對(duì)么?????但是控制臺(tái)打印texts,不是<span>T</span>這樣的,是Object [ #text ]?問(wèn)題2:setting.callback.call(this);?? 1、 我對(duì)call和this的用法一直沒(méi)搞懂,這里要實(shí)現(xiàn)的效果應(yīng)該是調(diào)用$('.ex2')..textyleF()里設(shè)置的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,就沒(méi)有<span style="display: inline-block; t…ier(0.77, 0, 0.175, 1);">所以調(diào)用了.call(this)的作用是什么?this指向變了?問(wèn)題3:①window.onload == $(window).on('load') ???????????? ② $(function($){});== $(document).ready()? ???????????? ③ ②在dom樹加載完就執(zhí)行,所以是在①之前執(zhí)行??????????? ④ (function($){...})(jquery);是自執(zhí)行匿名函數(shù)?也是在dom加載完運(yùn)行,那和$(function($){});有區(qū)別?
對(duì)于.replaceWith() .call(this) 在實(shí)際效果中的不解。
慕移動(dòng)2735134
2019-02-12 12:33:55