0

I have this array of objects. I want the value of 'duration' to change based on the width of the screen with an if/else statement.

This is what I've got right now, but I can't get it to work. I think it's because of the variable?

($.fn.defaults = {
    items: { start: 0 },
    scroll: {
        easing: "swing",
        duration: function (fztime) {
            var fztime;
            $(window).resize(function() {
                if($(window).width() >= 641) {
                    fztime = 7000;
                } else {
                    fztime = 500;
                }
            }).resize()
        },
        pauseOnHover: !1,
        event: "click",
        queue: !1 }
})

1 Answer 1

1

You need to return the value from the function, or, rather, set it directly with the ternary operator:

($.fn.defaults = {
  items: {
    start: 0
  },
  scroll: {
    easing: "swing",
    duration: $(window).width() >= 641 ? 7000 : 500
  },
  pauseOnHover: !1,
  event: "click",
  queue: !1
})

console.log($.fn.defaults)
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

As far as I can make out the function definition within the object seems superfluous. But I don't really know the wider context of your code.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.