- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用这个 plugin , 简单的新闻行情。
代码运行正常。
HTML
<h2>fade pattern</h2>
<div id="ticker-fade" class="ticker">
<ul>
<li>パターン1 テスト1</li>
<li>パターン1 テスト2</li>
<li>パターン1 テスト3</li>
<li>パターン1 テスト4</li>
<li>パターン1 テスト5</li>
</ul>
</div><!--/#ticker -->
<h2>roll pattern</h2>
<div id="ticker-roll" class="ticker">
<ul>
<li>パターン2 テスト1</li>
<li>パターン2 テスト2</li>
<li>パターン2 テスト3</li>
<li>パターン2 テスト4</li>
<li>パターン2 テスト5</li>
</ul>
</div><!--/#ticker -->
<h2>slide pattern</h2>
<div id="ticker-slide" class="ticker">
<ul>
<li>パターン2 テスト1</li>
<li>パターン2 テスト2</li>
<li>パターン2 テスト3</li>
<li>パターン2 テスト4</li>
<li>パターン2 テスト5</li>
</ul>
</div><!--/#ticker -->
和 JS:
$(function(){
$.simpleTicker($("#ticker-fade"),{'effectType':'fade'});
$.simpleTicker($("#ticker-roll"),{'effectType':'roll'});
$.simpleTicker($("#ticker-slide"),{'effectType':'slide'});
$.simpleTicker($("#ticker-one-item"),{'effectType':'fade'});
});
现在我需要通过点击改变行情效果。
<div id="update">Update</div>
JS:
$('#update').on('click', function()
{
$.simpleTicker($("#ticker-fade"),{'effectType':'roll'});
});
但是当我点击它时,效果是2,淡化和滚动。
我的问题是,是否可以重置之前的效果而不是通过点击将其替换为新效果?
最佳答案
我没有看到与此相关的任何文档,因此这是一个替代解决方案。
您可以使用 .clone()
在需要更改效果的地方保留 div 的克隆。然后,无论何时单击更新按钮,您都可以用克隆的替换原始文件,然后应用 roll
效果。
演示代码:
(function($) {
$.simpleTicker = function(element, options) {
var defaults = {
speed: 1000,
delay: 3000,
easing: 'swing',
effectType: 'slide'
}
var param = {
'ul': '',
'li': '',
'initList': '',
'ulWidth': '',
'liHeight': '',
'tickerHook': 'tickerHook',
'effect': {}
}
var plugin = this;
plugin.settings = {}
var $element = $(element),
element = element;
plugin.init = function() {
plugin.settings = $.extend({}, defaults, options);
param.ul = element.children('ul');
param.li = element.find('li');
param.initList = element.find('li:first');
param.ulWidth = param.ul.width();
param.liHeight = param.li.height();
element.css({
height: (param.liHeight)
});
param.li.css({
top: '0',
left: '0',
position: 'absolute'
});
switch (plugin.settings.effectType) {
case 'fade':
plugin.effect.fade();
break;
case 'roll':
plugin.effect.roll();
break;
case 'slide':
plugin.effect.slide();
break;
}
plugin.effect.exec();
}
plugin.effect = {};
plugin.effect.exec = function() {
param.initList.css(param.effect.init.css)
.animate(param.effect.init.animate, plugin.settings.speed, plugin.settings.easing)
.addClass(param.tickerHook);
if (element.find(param.li).length > 1) {
setInterval(function() {
element.find('.' + param.tickerHook)
.animate(param.effect.start.animate, plugin.settings.speed, plugin.settings.easing)
.next()
.css(param.effect.next.css)
.animate(param.effect.next.animate, plugin.settings.speed, plugin.settings.easing)
.addClass(param.tickerHook)
.end()
.appendTo(param.ul)
.css(param.effect.end.css)
.removeClass(param.tickerHook);
}, plugin.settings.delay);
}
}
plugin.effect.fade = function() {
param.effect = {
'init': {
'css': {
display: 'block',
opacity: '0'
},
'animate': {
opacity: '1',
zIndex: '98'
}
},
'start': {
'animate': {
opacity: '0'
}
},
'next': {
'css': {
display: 'block',
opacity: '0',
zIndex: '99'
},
'animate': {
opacity: '1'
}
},
'end': {
'css': {
display: 'none',
zIndex: '98'
}
}
}
}
plugin.effect.roll = function() {
param.effect = {
'init': {
'css': {
top: '3em',
display: 'block',
opacity: '0'
},
'animate': {
top: '0',
opacity: '1',
zIndex: '98'
}
},
'start': {
'animate': {
top: '-3em',
opacity: '0'
}
},
'next': {
'css': {
top: '3em',
display: 'block',
opacity: '0',
zIndex: '99'
},
'animate': {
top: '0',
opacity: '1'
}
},
'end': {
'css': {
zIndex: '98'
}
}
}
}
plugin.effect.slide = function() {
param.effect = {
'init': {
'css': {
left: (200),
display: 'block',
opacity: '0'
},
'animate': {
left: '0',
opacity: '1',
zIndex: '98'
}
},
'start': {
'animate': {
left: (-(200)),
opacity: '0'
}
},
'next': {
'css': {
left: (param.ulWidth),
display: 'block',
opacity: '0',
zIndex: '99'
},
'animate': {
left: '0',
opacity: '1'
}
},
'end': {
'css': {
zIndex: '98'
}
}
}
}
plugin.init();
}
$.fn.simpleTicker = function(options) {
return this.each(function() {
if (undefined == $(this).data('simpleTicker')) {
var plugin = new $.simpleTicker(this, options);
$(this).data('simpleTicker', plugin);
}
});
}
})(jQuery);
$(function() {
var cloned_fade = $("#ticker-fade").clone() //keep cloned of div
$('#update').on('click', function() {
$("#ticker-fade").replaceWith(cloned_fade); //replace whole ul with cloned
$.simpleTicker($("#ticker-fade"), {
'effectType': 'roll'
}); //then update
});
});
.ticker {
margin: 0;
padding: 10px;
width: 600px;
text-align: left;
border: #ccc 1px solid;
position: relative;
overflow: hidden;
background-color: #ffffff;
}
.ticker ul {
width: 100%;
position: relative;
margin: auto;
}
.ticker ul li {
width: 100%;
display: none;
}
/* DEMO */
body {
margin: 0 auto;
width: 600px;
}
#update {
color: red;
font-weight: bold;
cursor: pointer;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(function() {
$.simpleTicker($("#ticker-fade"), {
'effectType': 'fade'
});
});
</script>
<div id="update">Click to Update</div>
<h2>fade pattern</h2>
<div id="ticker-fade" class="ticker">
<ul>
<li>パターン1 テスト1</li>
<li>パターン1 テスト2</li>
<li>パターン1 テスト3</li>
<li>パターン1 テスト4</li>
<li>パターン1 テスト5</li>
</ul>
</div>
关于javascript - jQuery 重置 newsticker 的先前效果而不是通过单击替换为新效果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65453433/
我有一个“设置首选项”屏幕。它有一个 ListPreference 和一个 CheckBoxPreference。当我选择 ListPreference 的一项时,我想更改应用程序的日期格式。另外,通
我试图找到创 build 置/配置窗口的示例。单击菜单项中的“选项”操作可启动设置窗口。我想弄清楚如何从主窗口打开第二个窗口。以及新窗口如何将设置信息返回主窗口。尝试使用 QDialog 或一些继承的
我在 Lnux 上有 Qt 应用程序。我想为此创建一个可执行文件/设置以便在 Windows 上分发它并且不需要安装 Qt。我通过包含所有 dll 为此创建了可执行文件但要运行它,用户需要进入文件夹。
我正在尝试创建一个有点动态的 html 类,它根据类末尾包含的数字设置宽度 %。注意:类名将始终以“gallery-item-”开头 示例:div.gallery-item-20 = 20% 宽度 我
关闭。这个问题需要更多focused .它目前不接受答案。 想改进这个问题吗? 更新问题,使其只关注一个问题 editing this post . 关闭 6 年前。 Improve this qu
在我的应用程序中,我想记住一些变量,例如,如果用户登录过一次,那么他们将在下次重新打开应用程序时登录,或者如果他们决定禁用某些提醒,应用程序可以检查该变量是否是错误的,将不再显示该提醒。理想情况下,这
我在 Netbeans 中开发了一个应用程序,它连接到远程计算机的消息队列并发送消息。该应用程序还有其他功能。项目完成后,我清理并构建应用程序,然后 Netbeans 创建一个 jar 文件。 但我的
我创建了一个 Outlook 加载项,需要创建一个设置以使其可分发(我是新手,所以请原谅新手评论) Outlook -2010 Vs -2010 .Net 4.0 我读了一些地方,最简单的方法就是发
这个问题已经有答案了: 已关闭10 年前。 Possible Duplicate: How to make installer pack of Java swing Application Proje
这个问题肯定已经被很多人解决过很多次了,但是经过几个小时的研究,我仍然没有找到我要找的东西。 我有一个 ExportSettings.settings 文件,其中包含一堆设置( bool 值、字符串、
我想为我的项目创建一个安装程序,以便它可以安装在任何电脑上而无需安装头文件。我怎样才能做到这一点? 最佳答案 一般有两种分发程序的方法: 源代码分发(要构建的源代码)。最常见的方法是使用 GNU au
如何在这样的动态壁纸中创 build 置 Activity ? Example Picture 我只用一个简单的文本构建了设置 Activity ,但遇到了一些问题。第一个问题是我不能为此 Activ
我用 GUI 创建了一个简单的软件。它有几个源文件。我可以在我的编辑器中运行该项目。我认为它已经为 1.0 版本做好了准备。但我不知道如何为我的软件创 build 置/安装程序。 源代码是python
我的 SettingsActivity当前扩展了 Android Studio 生成的类,AppCompatPreferenceActivity扩展 PreferenceActivity . Acti
我正在使用 .NET 为 IE 开发工具栏。目前,我使用 gacutil 插入我的 .NET 程序集,并使用 regasm 注册我的 COM 程序集。 我想为项目创建一个设置 (MSI),但我似乎无法
在为设置页面创建 Activity 后,我注意到 if (mCurrentValue !== value) 中的 mCurrentValue !== value 返回警告: Identity equa
我在 Visual Studio 10 中创建了一个项目,该项目使用 Mysql 数据库和 Crystalreports 以及 它。但是我不知道如何进行自动安装 Mysql 和 Crystalrepo
我正在尝试在我的 C# 项目中使用 Sqlite 数据库,并且我在 IDE 中做得很好。我的问题是当我为我的项目制作安装包并安装它时,程序无法访问 sqlite 数据库。我也知道这是因为用户没有访问文
我有一个大型 Web 应用程序(带有 11 子系统的 ErP),我想使用 Microsoft WebPI 为它创建一个设置。 目前,我们每周向客户发送一次应用程序(用于每周更新)。 我们在此应用程序中
所以我对工资单申请的最终查询是 - 如何为薪资申请创 build 置? 我需要知道的一切- 如何将设置项目添加到我现有的解决方案 如何将解决方案中的文件添加到安装项目中,以及添加哪些文件添加和在什么文
我是一名优秀的程序员,十分优秀!