Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 单击特定字母后,如何获得原始条件?_Javascript_Jquery - Fatal编程技术网

Javascript 单击特定字母后,如何获得原始条件?

Javascript 单击特定字母后,如何获得原始条件?,javascript,jquery,Javascript,Jquery,代码如下: $(文档).ready(函数(){ $('div').html(函数(i,html){ var chars=$.trim(html).split(“”); 返回“”+字符联接(“”)+“”; }); $('div')。单击(函数(){ $('span')。每个(函数(){ $(this.css)({ “位置”:“绝对” }); $(此)。设置动画({ 左:Math.random()*window.outerWidth/2, 顶部:Math.random()*window.outer

代码如下:

$(文档).ready(函数(){
$('div').html(函数(i,html){
var chars=$.trim(html).split(“”);
返回“”+字符联接(“”)+“”;
});
$('div')。单击(函数(){
$('span')。每个(函数(){
$(this.css)({
“位置”:“绝对”
});
$(此)。设置动画({
左:Math.random()*window.outerWidth/2,
顶部:Math.random()*window.outerHeight/2,
});
});
});
});
html,
身体{
宽度:100%;
身高:100%;
}
div{
字体系列:Arial;
字体大小:9vw;
文本转换:大写;
}


堆栈溢出
您只需删除使用
$(this)添加到span的
css
。查找(“span”).css({“left”:“…})
并添加一些类来标识文本的当前状态

演示代码
$(文档).ready(函数(){
$('div').html(函数(i,html){
var chars=$.trim(html).split(“”);
返回“”+字符联接(“”)+“”;
});
$('div')。单击(函数(){
if($(this).hasClass(“已”)){
//删除添加到span的css
$(this.find(“span”).css({
“左”:“左”,
“顶部”:“,
“位置”:”
});
//已删除类
$(this.removeClass(“已经”)
}否则{
//添加要标识的类
$(this.addClass(“已经”)
$('span')。每个(函数(){
$(this.css)({
“位置”:“绝对”
});
$(此)。设置动画({
左:Math.random()*window.outerWidth/2,
顶部:Math.random()*window.outerHeight/2,
});
});
}
});
});
html,
身体{
宽度:100%;
身高:100%;
}
div{
字体系列:Arial;
字体大小:9vw;
文本转换:大写;
}


堆栈溢出
添加一个标志以检查是否需要随机字符,然后将位置重置为相对,将左和上重置为0

$(文档).ready(函数(){
var isRandom=假;
$('div').html(函数(i,html){
var chars=$.trim(html).split(“”);
返回“”+字符联接(“”)+“”;
});
$('div')。单击(函数(){
isRandom=!isRandom;
if(isRandom){
$('span')。每个(函数(){
$(this.css)({
“位置”:“绝对”
});
$(此)。设置动画({
左:Math.random()*window.outerWidth/2,
顶部:Math.random()*window.outerHeight/2,
});
});
}否则{
$('span')。每个(函数(){
$(this.css)({
“位置”:“相对”
});
$(此)。设置动画({
左:0,,
排名:0,
});
});
}
});
});
html,
身体{
宽度:100%;
身高:100%;
}
div{
字体系列:Arial;
字体大小:9vw;
文本转换:大写;
}


堆栈溢出
这是一个错误的答案吗?location.reload()@不幸的是,是的。不应该刷新整个页面。可以使用第二个html div元素吗?或者,只使用一个?你能在CSS中使用z索引吗?那么.show()和.hide()呢?可以使用.html()和这样的变量吗?非常感谢你!!基于此,我刚刚写了一个新问题。这里是链接:–如果你也能帮我,我将非常感激!