已解决 请问这要如何随机出现 array

  • 欢迎 游客 您的光临,下载之前请先阅读 积分规则(暂行) 。任何技术问题请在论坛提问,本站定制插件、模板主题售前、售后问题请联系QQ:5916171
UID
17
注册
2017/09/27
消息
18
反馈评分
70
黄金
3.0G
请问这要如何随机出现
例如点击页面首先显示"民主"
重新整理页面后点击页面却先显示"爱国"





<script type="text/javascript">
var a_idx = 0;
jQuery(document).ready(function($) {
$("body").click(function(e) {
var a = new Array("1","2","3","4","5");
var $i = $("<span />").text(a[a_idx]);
a_idx = (a_idx + 1) % a.length;
var x = e.pageX,
y = e.pageY;
$i.css({
"z-index": 999999999999999999999999999999999999999999999999999999999999999999999,
"top": y - 20,
"left": x,
"position": "absolute",
"font-weight": "bold",
"color": "#ff8000"
});
$("body").append($i);
$i.animate({
"top": y - 180,
"opacity": 0
},
1500,
function() {
$i.remove();

});
});
});
</script>
 

死了算了

管理成员
CNXFans
UID
1
注册
2017/07/28
消息
1,101
解决方案
21
反馈评分
5,167
黄金
32,939.5G
:ecms16:我也不知道啊。会话里已经回复你了
 
  • 支持
反馈: 花花❤

reishi

林子大
UID
4
注册
2017/09/01
消息
13
反馈评分
20
黄金
20.0G
JavaScript:
<script>
(function () {
var coreSocialistValues = ["富强", "民主", "文明", "和谐", "自由", "平等", "公正", "法治", "爱国", "敬业", "诚信", "友善"],
index = Math.floor(Math.random() * coreSocialistValues.length);
document.body.addEventListener('click', function (e) {
if (e.target.tagName == 'A') {
return;
}
var x = e.pageX,
y = e.pageY,
span = document.createElement('span');
span.textContent = coreSocialistValues[index];
index = (index + 1) % coreSocialistValues.length;
span.style.cssText = ['z-index: 9999999; position: absolute; font-weight: bold; color: #ff6651; top: ', y - 20, 'px; left: ', x, 'px;'].join('');
document.body.appendChild(span);
animate(span);
});

function animate(el) {
var i = 0,
top = parseInt(el.style.top),
id = setInterval(frame, 16.7);

function frame() {
if (i > 180) {
clearInterval(id);
el.parentNode.removeChild(el);
} else {
i += 2;
el.style.top = top - i + 'px';
el.style.opacity = (180 - i) / 180;
}
}
}
}());
</script>


</body>前,试试。