Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
Jayson

Code doesn't seem to work on Safari

Warning: Please note

This thread was started before GSAP 3 was released. Some information, especially the syntax, may be out of date for GSAP 3. Please see the GSAP 3 migration guide and release notes for more information about how to update the code to GSAP 3's syntax. 

Recommended Posts

Hi guys been trying to make an animation for work where there is an image that goes from left to right with a clipping path to make the image have some sort of cut on the top. My problem is that it doesn't work on safari but somehow works on every other browser even firefox.

 

I linked all the assets needed in the same folder to make the animation.

 

 

<!DOCTYPE html>
<html>
    <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>test</title>
        <style type="text/css">
#bg01 img{clip-path: url(#clip1); position: absolute; top: 0; left: 0;}
#svg-defs {position: absolute; width: 0px;height: 0px;}
</style>

<script src="https://s0.2mdn.net/ads/studio/cached_libs/tweenmax_1.18.0_499ba64a23378545748ff12d372e59e9_min.js"></script>
</head>
      <body>
            <svg id="svg-defs">
                <defs>
                    <clipPath id="clip1">
                        <rect id="mask1" x="0" y="150" transform="matrix(1 0.2 0 1 0 0)" class="st0" width="170" height="610"/>
                    </clipPath>
                </defs>
        </svg>

            <div id="myAd">
                <div id="bg01">
                    <img id="img1"  src="bg_01.jpg" width="160" height="600"/>
                </div>
            </div>
<script type="text/javascript" src="TweenMax.min.js"></script>
<script type="text/javascript">


var start = 0.1;
var trans = 0.3;
var bg1_time = 3;
var tl = new TimelineMax();
var tl1 = new TimelineMax();

tl1.from('#mask1', trans, {
        x: -170,y: -35,ease: Power1.Out})

                tl.to([tl1],
                                start,
                                "sequence",
                                "-=0.45")

    </script>
    </body>

  </html>

 

That was the original code.

I made the animation slower and tried all i can to fix it on this code but some reason the only way it seemed to work is if i constantly resized the browser.

 

<!DOCTYPE html>
<html>
    <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>test</title>
        <style type="text/css">
#bg01 img{
    /* clip-path: url(#clip1); */
    -webkit-clip-path: url(#clip1);
    position: absolute; top: 0; left: 0;
}
body{
    width: 200px;
    height: 800px;
}
#myAd{
    width: 200px;
    height: 800px;
}
.svg-defs {position: absolute; width: 0px;height: 0px;}
</style>
<!-- <script src="https://s0.2mdn.net/ads/studio/cached_libs/tweenmax_1.18.0_499ba64a23378545748ff12d372e59e9_min.js"></script> -->

<script type="text/javascript" src="TweenMax.min.js"></script>

<script type="text/javascript">

    function resize(){
        console.log("tick");
        window.requestAnimationFrame = window.requestAnimationFrame
    || window.mozRequestAnimationFrame
    || window.webkitRequestAnimationFrame
    || window.msRequestAnimationFrame
    || function(f){return setTimeout(f, 1000/60)} // simulate calling code 60

        requestAnimationFrame(function(){
            console.log("requested")
        })
    }

    function main(){

        // TweenLite.ticker.useRAF(false);
        // TweenMax.lagSmoothing(1000, 16);


        var ad = document.getElementById('myAd');
        var mask1 = document.getElementById('mask1');
        var img = document.getElementById('img1');

        function update(){
            console.log(img)
            // console.log("tick");
            // window.dispatchEvent(new Event('resize'))
        }

        setInterval(update, 1000);

        // TweenMax.ticker.addEventListener("tick", update);

        var start = 0.1;
        var trans = 5;
        var bg1_time = 3;
        var tl = new TimelineMax();
        var tl1 = new TimelineMax();

        var mask1 = document.getElementById("mask1");
        var clip1 = document.getElementById("clip1");
        var ad = document.getElementById("myAd")

        tl1.from(ad, 10, {
                x: 0,y: 0
        })

        tl.from(mask1, trans, {
                x: -170,y: -35,ease: Power1.Out})


        // tl1.from(mask1, trans, {
        //         x: -170,y: -35,ease: Power1.Out})

        // tl.to([tl1],
        //                 start,
        //                 "sequence",
        //                 "-=0.45")

        // TweenMax.ticker.removeEventListener("tick", update);

        }

        </script>
</head>
      <body onLoad="main();" onResize="resize();">
            <svg class="svg-defs">
                    <clipPath id="clip1">
                        <rect id="mask1" x="0" y="150" transform="matrix(1 0.2 0 1 0 0)" class="st0" width="170" height="610"/>
                    </clipPath>
        </svg>

            <div id="myAd">
                <div id="bg01">
                    <img id="img1" class="" src="bg_01.jpg" width="160" height="600"/>
                </div>

    </body>

  </html>

 

TweenMax.min.js

mine_testing for browsers.html

bg_01.jpg

Share this post


Link to post
Share on other sites

Cupertino silently dropped clip-path support in the background when was in the middle of a campaign based on it.

  • Like 2

Share this post


Link to post
Share on other sites
3 minutes ago, Oliver16Years said:

Cupertino silently dropped clip-path support in the background when was in the middle of a campaign based on it.

Not exactly sure what you mean by that. are you trying to say that there is no SVG on safari? And how about the animation?

Share this post


Link to post
Share on other sites

Sorry my fault, no. There is SVG in Safari, but no standard DOM support for .style.clip = "rect(0px 100px 10px 0px)";

If You could make a CodePen example we could debug it. But at first glance i think the DOM and the SVG can't be mixed in this way.
You have to put the image into SVG context to be able to clip it. ( <image> tag ).

https://developer.mozilla.org/en-US/docs/Web/SVG/Element/image

  • Like 2

Share this post


Link to post
Share on other sites
19 minutes ago, Oliver16Years said:

Sorry my fault, no. There is SVG in Safari, but no standard DOM support for .style.clip = "rect(0px 100px 10px 0px)";

If You could make a CodePen example we could debug it. But at first glance i think the DOM and the SVG can't be mixed in this way.
You have to put the image into SVG context to be able to clip it. ( <image> tag ).

https://developer.mozilla.org/en-US/docs/Web/SVG/Element/image

Hey I'm not the most experienced developer and not exactly sure how to make it into Codepen seeing how i kind of put it all in one Html file.  

Share this post


Link to post
Share on other sites

Hey @Jayson!

 

Welcome to the forums!

 

20 minutes ago, Jayson said:

Hey I'm not the most experienced developer and not exactly sure how to make it into Codepen seeing how i kind of put it all in one Html file.  

 

Not to worry. It will actually be a good stepping stone for you to get a CodePen account (or in any other online live editing site) for it will give you a nice easy place for you to prototype, make it super easy for you to collaborate and help others help you.

 

If you don't have one, make an account, CodePen has a free one, once you have it. Create a new pen ( button on the top right corner) and you will see the screen split into two columns. One is the code editor, the other the result of your code. The editor is split into three sections, HTML, JS and CSS. Drop your relevant code in the associated section.

 

For the HTML you only need to place what is inside the <body> tag. CodePen will add all the rest. Finally to add GSAP, click on the 'settings' (again top right) button, once the modal is open, click on the 'javascript' tab and look at the bottom, there will be a 'quick add' dropdown. Choose Greensock TweenMax and you will be all set to go.

 

We'll now be able to fork your code, tinker with it and offer suggestions.

  • Like 4

Share this post


Link to post
Share on other sites

Like Dipscom said, it'll be best for you to spend a few mins setting up a CodePen account and initial pen to help us help you out.
I'm not able to see what's going on without rebuilding your file on my end but...

Just a quick glance at your code, my initial thought was do you NEED to be using clip path for the mask effect. Looks like you're using a simple rectangle to clip with. You could nest the content in a container, use overflow:hidden, and adjust or animate the width and height of the container to mask it. If it's an angled mask, you could rotate the container one way, and then rotate the child nested content in the other direction to make it look straight again (if that makes sense).

  • Like 3

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Warning: Please note

This thread was started before GSAP 3 was released. Some information, especially the syntax, may be out of date for GSAP 3. Please see the GSAP 3 migration guide and release notes for more information about how to update the code to GSAP 3's syntax. 


  • Recently Browsing   0 members

    No registered users viewing this page.

×