简体   繁体   English

使用jquery .css()添加自定义样式名称

[英]Add custom style name using jquery .css()

I am working with Animate.css and trying to assign the duration, delay and looping options, but the command is being ignored. 我正在使用Animate.css并尝试分配持续时间,延迟和循环选项,但是该命令被忽略了。 I think it is because propertyName is not recognized and so is just ignored. 我认为这是因为propertyName无法识别,因此被忽略了。 I would like to apply it right to the element instead of appending a tag to the body with the info. 我想将其直接应用于元素,而不是在标签上添加带有信息的正文。

.css(
  {
    "-vendor-animation-duration": "7s", 
    "-vendor-animation-delay": "2s", 
    "-vendor-animation-iteration-count": "infinite"
  }
);

Is there a way to force it to add something it doesn't recognize? 有没有办法强迫它添加无法识别的内容?

Update - Adding an example,it looks messy, but it is all dynamically added using jquery as a preview. 更新-添加一个示例,它看起来很杂乱,但是都使用jquery作为预览来动态添加。 Later it will be called from the database and assigned. 稍后,它将从数据库中调用并进行分配。

<div data-layer="0" data-type="sliderLayer" data-slide="0" 
data-positioningtypewidth="px" data-positioningtypeheight="px" 
data-positioningtypeleft="px" data-positioningtypetop="px" data-id="0" 
class="resizable draggable canvasItem sliderLayer-0 slide-0 draggable-0 
ui-draggable ui-draggable-handle ui-resizable bounce.slide animated" 
style="background-color: rgb(204, 17, 102); z-index: 100; animation-duration: 
1000ms; opacity: 0.88; display: block; width: 455px; height: 115px; border-
radius: 25.15px; background-size: 50px 50px; background-image: -moz-linear-
gradient(-45deg, rgba(255, 255, 255, 0.2) 25%, transparent 25%, transparent 
50%, rgba(255, 255, 255, 0.2) 50%, rgba(255, 255, 255, 0.2) 75%, transparent 
75%, transparent); box-shadow: 0px 0px 8px rgb(119, 61, 161);">

If no other inline styles are being used on the element, you could use the attr function to set the styles inline 如果元素上没有使用其他内联样式,则可以使用attr函数设置内联样式

.attr("style","-vendor-animation-duration: 7s;-vendor-animation-delay: 2s; -vendor-animation-iteration-count: infinite;");

EDIT: 编辑:

If inline styles are already being applied, you could try defining these rules for a class in css, then add the class using jQuery 如果已经应用了内联样式,则可以尝试在CSS中为类定义这些规则,然后使用jQuery添加类

<style>
    .vendor-animation {
        -vendor-animation-duration: 7s; 
        -vendor-animation-delay: 2s; 
        -vendor-animation-iteration-count: infinite;
    }
</style>
<script>
    $('#element').addClass('vendor-animation');
</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM