doulutian4843 2015-10-21 05:13
浏览 79
已采纳

用于在网页中按需加载图像,视频的脚本

Some bulletin board systems or content management systems are allowing a user to write a post with images and videos. Image and videos can be inserted with tags img, embed, etc.

What I want to do is, I want to make a reader decide to load images and videos or not. In other words, I want to put some placeholders saying Click to load. Images below are what I want. But it's a feature of a web browser. I want to implement it in either a server-side or a client-side.

A reason that I want this feature is, some large images, GIFs and autoplay videos are not favorable to mobile phones or to some people.

http://cdn.osxdaily.com/wp-content/uploads/2011/06/click-to-play-flash-example-chrome-300x251.jpg

http://cdn9.howtogeek.com/wp-content/uploads/2014/04/click-to-play-plug-ins4.png

A simple idea is that, examining tags img and embed with regular expression in a certain known area, e.g. <div id="contents"></div>. And if regular expression hits, replacing it with placeholders and a custom-made javscript or PHP function click_to_load().

Before start from the scratch, I'd like to know whether there is a such library already implementing this.

  • 写回答

1条回答 默认 最新

  • donglu0494 2015-10-21 06:38
    关注

    you can do on demand loading in pure JavaScript if you want. If you want to write the function click_to_load() in JavaScript, all you need to do is have an image in HTML with no source, then change the source in JavaScript with the click of a button.

    function click_to_load() {
        document.getElementById("image").src = "http://i.imgur.com/AXTI1Gr.gif";
    }
    

    this function changes an images source to a .gif of a cat

    now just add a button with this javascript

    document.getElementById("button").onclick = click_to_load;
    

    example code that works

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c