Javascript 从jquery函数中排除类时出现问题
我有一个基于Shuffletters.js对字母进行置乱的函数。它工作得很好,但我似乎不能排除嵌套在我目标类中的类 所以我想在我的菜单项中对字符进行置乱。因此,我给它们一类Javascript 从jquery函数中排除类时出现问题,javascript,jquery,Javascript,Jquery,我有一个基于Shuffletters.js对字母进行置乱的函数。它工作得很好,但我似乎不能排除嵌套在我目标类中的类 所以我想在我的菜单项中对字符进行置乱。因此,我给它们一类.shuffle,并像这样调用函数: $(function(){ var container = $(".shuffle") container.shuffleLetters(); }); 其中.shuffletters使用插件。问题是它会扰乱嵌套在该菜单项中的所有字符,这是我不想要的 我已经阅读了。not方
.shuffle
,并像这样调用函数:
$(function(){
var container = $(".shuffle")
container.shuffleLetters();
});
其中.shuffletters使用插件。问题是它会扰乱嵌套在该菜单项中的所有字符,这是我不想要的
我已经阅读了。not
方法,但无法使其正常工作
以下是我正在尝试的:
<li class="shuffle">title
<li class="no-shuffle">sub-title
</li>
</li>
但这不起作用
谁能给我指出正确的方向,绞尽脑汁好几个小时
一如既往,提前感谢
编辑:以下是:
(函数($){
$.fn.shuffletters=函数(prop){
变量选项=$.extend({
“步骤”:8,//字母应该更改多少次
“fps”:25,//帧/秒
“文本”:“”//使用此文本而不是内容
“回调”:函数(){}//动画完成后运行
},道具)
返回此值。每个(函数(){
var el=$(此),
str=“”;
//使用标志防止并行动画;
如果(标高数据(‘动画’){
返回true;
}
el.数据(“动画”,真实);
if(options.text){
str=options.text.split(“”);
}
否则{
str=el.text().split(“”);
}
//类型数组保存每个字符的类型;
//字母保持非空格字符的位置;
变量类型=[],
字母=[];
//在字符串的所有字符中循环
对于(变量i=0;ilen){
//动画已完成。正在更新
//标记并触发回调;
el.数据(“动画”,假);
选项。回调(el);
返回;
}
//所有的工作都在这里完成
对于(i=Math.max(开始,0);i
尝试在中包装文本节点“title”。在span
元素中洗牌li
(函数($){
$.fn.shuffletters=函数(prop){
变量选项=$.extend({
“步骤”:8,//字母应该更改多少次
“fps”:25,//帧/秒
“文本”:“”//使用此文本而不是内容
“回调”:函数(){}//动画完成后运行
},道具)
返回此值。每个(函数(){
var el=$(此),
str=“”;
//使用标志防止并行动画;
如果(标高数据(‘动画’){
返回true;
}
el.数据(“动画”,真实);
if(options.text){
str=options.text.split(“”);
}
否则{
str=el.text().split(“”);
}
//类型数组保存每个字符的类型;
//字母保持非空格字符的位置;
变量类型=[],
字母=[];
//在字符串的所有字符中循环
对于(变量i=0;ilen){
//动画已完成。正在更新
//标记并触发回调;
el.数据(“动画”,假);
选项。回调(el);
返回;
}
//所有的工作都在这里完成
对于(i=Math.max(开始,0);i$(function(){
var container = $(".shuffle").not('.no-shuffle')
container.shuffleLetters();
});
(function($){
$.fn.shuffleLetters = function(prop){
var options = $.extend({
"step" : 8, // How many times should the letters be changed
"fps" : 25, // Frames Per Second
"text" : "", // Use this text instead of the contents
"callback" : function(){} // Run once the animation is complete
},prop)
return this.each(function(){
var el = $(this),
str = "";
// Preventing parallel animations using a flag;
if(el.data('animated')){
return true;
}
el.data('animated',true);
if(options.text) {
str = options.text.split('');
}
else {
str = el.text().split('');
}
// The types array holds the type for each character;
// Letters holds the positions of non-space characters;
var types = [],
letters = [];
// Looping through all the chars of the string
for(var i=0;i<str.length;i++){
var ch = str[i];
if(ch == " "){
types[i] = "space";
continue;
}
else if(/[a-z]/.test(ch)){
types[i] = "lowerLetter";
}
else if(/[A-Z]/.test(ch)){
types[i] = "upperLetter";
}
else {
types[i] = "symbol";
}
letters.push(i);
}
el.html("");
// Self executing named function expression:
(function shuffle(start){
// This code is run options.fps times per second
// and updates the contents of the page element
var i,
len = letters.length,
strCopy = str.slice(0); // Fresh copy of the string
if(start>len){
// The animation is complete. Updating the
// flag and triggering the callback;
el.data('animated',false);
options.callback(el);
return;
}
// All the work gets done here
for(i=Math.max(start,0); i < len; i++){
// The start argument and options.step limit
// the characters we will be working on at once
if( i < start+options.step){
// Generate a random character at thsi position
strCopy[letters[i]] = randomChar(types[letters[i]]);
}
else {
strCopy[letters[i]] = "";
}
}
el.text(strCopy.join(""));
setTimeout(function(){
shuffle(start+1);
},1000/options.fps);
})(-options.step);
});
};
function randomChar(type){
var pool = "";
if (type == "lowerLetter"){
pool = "abcdefghijklmnopqrstuvwxyz0123456789";
}
else if (type == "upperLetter"){
pool = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
}
else if (type == "symbol"){
pool = ",.?/\\(^)![]{}*&^%$#'\"";
}
var arr = pool.split('');
return arr[Math.floor(Math.random()*arr.length)];
}
})(jQuery);