【问题标题】:vuejs infinite bounce method in component组件中的vuejs无限反弹方法
【发布时间】:2018-04-06 09:59:34
【问题描述】:

我有 vuejs 组件来显示图像块。

这是我的 html,调用了 4 次组件:

<div id="activities" class="row text-center justify-content-center activities">
    <zpeakimage type="art" text="{{ art_text }}" img="{{asset('images/art.png')}}" target="/list/art"></zpeakimage>
    <zpeakimage type="run" text="{{ run_text }}" img="{{asset('images/run.png')}}" target="/list/run"></zpeakimage>
    <zpeakimage type="eat" text="{{ eat_text }}" img="{{asset('images/eat.png')}}" target="/list/eat"></zpeakimage>
    <zpeakimage type="party" text="{{ party_text }}" img="{{asset('images/party.png')}}" target="/list/party"></zpeakimage>
</div>

我的 vue-zpeakimage.js :

Vue.component('zpeakimage', {
  delimiters: ['${', '}'],
  props: ['type', 'text', 'img', 'target'],
  template: '<div class="col-3" style="padding-top: 20px;"><h3><a @mouseover="imgBounce(type)" :title="text" :href="target"><span> <img style="width:220px;" :id="type" :src="img" :alt="text"> </span></a></h3><span> ${text} </span></div>',
  methods: {
    imgBounce: function doBounce(Id) {
        $('#'+Id).effect('bounce', {times: 3}, 500);
    }
  }
});

new Vue({
  el: '#activities'
});

鼠标悬停时img弹跳,但我想在鼠标悬停时无限上下动画..

【问题讨论】:

  • 您实际上告诉它只反弹 3 次:$('#'+Id).effect('bounce', {times: 3}, 500); - 将该属性更改为您需要传递给 effect 函数的任何内容,以使其无限循环。此外,这个问题显然是关于第三方库或一些与您提供的内容无关的代码,因此无法以合理的方式回答。

标签: vue.js


【解决方案1】:

因此,您希望图像在鼠标悬停在其上时会永远反弹。你想用 jQuery ui 做反弹。

https://jsfiddle.net/50wL7mdz/273936/

<div id="activities" class="row text-center justify-content-center activities">
    <zpeakimage type="art" text="art_text" :img="asset('images/art.png')" target="/list/art"></zpeakimage>
    <zpeakimage type="run" text="run_text" :img="asset('images/run.png')" target="/list/run"></zpeakimage>
    <zpeakimage type="eat" text="eat_text" :img="asset('images/eat.png')" target="/list/eat"></zpeakimage>
    <zpeakimage type="party" text="party_text" :img="asset('images/party.png')" target="/list/party"></zpeakimage>
</div>

Vue.component('zpeakimage', {
  delimiters: ['${', '}'],
  props: ['type', 'text', 'img', 'target'],
  template: '<div class="col-3" style="padding-top: 20px;"><h3><a @mouseover="imgBounce" :title="text" :href="target"><span> <img style="width:220px;" :id="type" ref="id" :src="img" :alt="text"> </span></a></h3><span> ${text} </span></div>',
  data () {
  return {interval: null}
  },
  methods: {
    imgBounce: function () {
    if (this.interval) return
    var self = this
    this.interval = setInterval(function() {
        $(self.$refs.id).effect('bounce', {times: 3}, 500);
    } ,1000)
    }
  },
  destroyed: function() {
    if (this.interval)
        clearInterval(this.interval)
  }
})

new Vue({
  el: '#activities'
});

【讨论】:

  • 谢谢。抱歉,如果我在 HTML 中设置 ':type', ':text' ...,则 vuejs 在鼠标悬停时会返回错误。 javascript中的双运算符*是什么意思?是否等于 * ?
猜你喜欢
  • 1970-01-01
  • 2017-11-20
  • 2017-04-09
  • 2018-02-08
  • 2018-11-18
  • 1970-01-01
  • 1970-01-01
  • 2020-07-13
  • 2020-05-30
相关资源
最近更新 更多