


Practical development of JavaScript using DeviceOne (4) imitating Youku video application_javascript skills
Before you start development, you first need to consider the differences in the system. For example, does the iOS phone have a back button? Therefore, when developing, you must consider that the secondary decryption requires a back button, otherwise the iOS phone will fall into This page cannot be returned.
The Android system has a back button. In this case, the user needs to press the back button twice within 3 seconds before exiting the system, so as to prevent the user from accidentally pressing the back button. The specific code is implemented as follows:
[mw_shl_code=javascript,true]page.on("back", function(){ if (canBack) { global.exit(); } else { nf.toast("再按一次退出优酷"); canBack = true; delay3.start(); } }); var delay3 = mm("do_Timer"); delay3.delay = 3000; delay3.interval = 1000; delay3.on("tick", function(){ this.stop(); canBack = false; });[/mw_shl_code]
Imitate Youku Video to implement four main interfaces. You can switch between pages by sliding the page left or right, or you can switch between pages by clicking the bottom button, and the color of the bottom button will also change as the page switches. Change. This function is implemented through the slideview component, and the effect picture is as follows:
Bottom changes:
The code is implemented as follows:
[mw_shl_code=javascript,true] function subChange(num,button,imgs,lbs) { var strings = ["下载","频道","订阅","我的"]; button.text = strings[num]; var url = [ "source://image/main/shouye", "source://image/main/pindao", "source://image/main/dingyue", "source://image/main/wode" ]; for(var i = 0 ; i < 4 ; i++) { imgs.source = url; lbs.fontColor = "222222FF"; } imgs[num].source += "b"; lbs[num].fontColor = "0080FFFF"; for(var i = 0 ; i < 4 ; i++) { imgs.source += ".png"; } img.visible = false; bt.visible = false; } function indexChange(num,sv,button,imgs,lbs,img,bt) { sv.set({index: num}); sv.refreshItems(); subChange(num,button,imgs,lbs); } do_button.on("touch",function(data, e){ if(do_button.text == "下载") { app.openPage("source://view/download.ui",""); } }); //点击底部按钮实现主界面以及底部图片颜色的切换 var action_imgs = [ui("img_0"), ui("img_1"), ui("img_2"), ui("img_3")]; var action_lbs = [ui("lb_0"), ui("lb_1"), ui("lb_2"), ui("lb_3"),]; do_slideview_1.bindItems(listdata ); listdata.addData([ {template : 0}, {template : 1}, {template : 2}, {template : 3} ]); do_slideview_1.refreshItems({}); var shouye = ui("shouye"); shouye.on("touch",function(data, e){ indexChange(0,do_slideview_1,do_button,action_imgs,action_lbs,imageview,do_button_3); }); var pindao = ui("pindao"); pindao.on("touch",function(data, e){ indexChange(1,do_slideview_1,do_button,action_imgs,action_lbs,imageview,do_button_3); }); var dingyue = ui("dingyue"); dingyue.on("touch",function(data, e){ indexChange(2,do_slideview_1,do_button,action_imgs,action_lbs,imageview,do_button_3); }); var wode = ui("wode"); wode.on("touch",function(data, e){ indexChange(3,do_slideview_1,do_button,action_imgs,action_lbs,imageview,do_button_3); }); //滑动主界面实现底部图片的切换 do_slideview_1.on("indexChanged",function(data, e){ subChange(data,do_button,action_imgs,action_lbs); }); [/mw_shl_code]
Switching between homepage posters is similar to switching between pages, but switching between posters also implements the function of automatic timing switching, switching every three seconds. Time control is implemented by do_timer. When using this component, the time period It cannot be 100, otherwise the ios system will have incompatibility issues. The picture and code are as follows:
Picture:
Code:
[mw_shl_code=javascript,true] var ind = 0; timer.delay = 0; timer.interval = 1000; timer.start({}); timer.on("tick", function(){ DURATION++; if(DURATION == 3){ ind =(ind+1)%4 movieview.set({index: ind}); movieview.refreshItems(); DURATION = 0; } });[/mw_shl_code]
Click the download button in the upper left corner of the main interface to enter the download interface. After clicking download, the application will download another picture poster from the Internet to replace the original poster. The download progress is displayed through the progress bar, and the download function is through the http component. The download method is implemented, and the progress bar is implemented through the do_progressbar component. The rendering and code implementation are as follows:
Effect:
Code:
[mw_shl_code=javascript,true] var http = mm("do_Http"); http.timeout = 30000; http.contentType = "application/json"; http.url = "http://h.hiphotos.baidu.com/baike/c0%3Dbaike60%2C5%2C5%2C60%2C20%3Bt%3Dgif/sign=88e9903f8735e5dd8421ad8d17afcc8a/f9198618367adab48dc66b2e89d4b31c8701e44d.jpg"; http.on("success", function(data) { do_imageview_1.source="data://xiazai.png"; do_button_2.text = "下载成功"; }); http.on("progress", function(data) { do_ProgressBar_0.progress = data.currentSize * 100 / data.totalSize; lb_progress.text = data.currentSize * 100 / data.totalSize + "%"; }); do_button_2.on("touch",function(data, e){ http.download("data://xiazai.png"); });[/mw_shl_code]
There are three buttons in the upper right corner. After clicking the first button from the left, a search interface will pop up. The search box of the search interface is implemented by the textfield component.
After clicking the second button, the interface for scanning the QR code will pop up. This interface implements the function of scanning the QR code. After successful scanning, the user will be prompted that the scan is successful. The QR code is implemented by the do_BarcodeView component. The implementation picture and implementation code are as follows Shown:
Code:
[mw_shl_code=javascript,true]var nf = sm("do_Notification"); //根据ID获取BarcodeView实例对象; var barcode = ui("do_BarcodeView_1"); start(); function start(){ //开始启动扫描 barcode.start(function(data, e) { //扫描成功,执行回调函数 var result = JSON.stringify(data); nf.alert("扫描二维码成功!", "完成") }); } var btn = ui("btn_restart"); btn.on("touch", function(data, e) { start(); }) [/mw_shl_code]
After clicking the third button, a picture will pop up on the interface. After pressing the button again, the picture will disappear. The effect is as follows:
Video playback function
Click on any poster on the homepage to enter the video playback interface. Click the play button to play the video. This function is implemented by the do_VideoView component. The effect and code are as follows:
Code:
[mw_shl_code=javascript,true]var page = sm("do_Page"); var app = sm("do_App"); var do_VideoView_1 = ui("do_VideoView_1"); var do_Button_1 = ui("do_Button_1"); var do_Button_2 = ui("do_Button_2"); var do_Button_3 = ui("do_Button_3"); page.on("back", function(){ app.closePage() }); ui("action_back").on("touch", function(){ app.closePage() }); do_Button_1.on("touch", function(data, e) { if(do_Button_1.text == "播放") { do_VideoView_1.play(0); do_Button_1.text = "暂停"; } else if(do_Button_1.text == "暂停") { do_VideoView_1.pause(); do_Button_1.text = "继续"; } else if(do_Button_1.text == "继续") { do_VideoView_1.resume(); do_Button_1.text = "暂停"; } }); do_Button_2.on("touch", function(data, e) { do_Button_1.text = "播放"; do_VideoView_1.stop(); });[/mw_shl_code]
Click the "Poke, everything you like to see is here" button, and the main page will jump directly to the subscription page. The implementation of this function relies on data exchange between pages. The page component is used to define an event1 event in the logic code of the index page, and the fire function of the page component is called in the logic code of the shouye page to trigger the event1 event.
The rendering is as follows:
The logic code is as follows:
index page:
[mw_shl_code=javascript,true]page.on("event1", function(data, e) { indexChange(2,do_slideview_1,do_button,action_imgs,action_lbs,imageview,do_button_3); });[/mw_shl_code] shouye页面: [mw_shl_code=javascript,true]do_Button_0.on("touch",function(data, e) { page.fire("event1",""); });[/mw_shl_code]
The above is the practical development of JavaScript using DeviceOne (4) imitating Youku video application introduced by the editor. I hope you like it.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Frequently Asked Questions and Solutions for Front-end Thermal Paper Ticket Printing In Front-end Development, Ticket Printing is a common requirement. However, many developers are implementing...

There is no absolute salary for Python and JavaScript developers, depending on skills and industry needs. 1. Python may be paid more in data science and machine learning. 2. JavaScript has great demand in front-end and full-stack development, and its salary is also considerable. 3. Influencing factors include experience, geographical location, company size and specific skills.

JavaScript is the cornerstone of modern web development, and its main functions include event-driven programming, dynamic content generation and asynchronous programming. 1) Event-driven programming allows web pages to change dynamically according to user operations. 2) Dynamic content generation allows page content to be adjusted according to conditions. 3) Asynchronous programming ensures that the user interface is not blocked. JavaScript is widely used in web interaction, single-page application and server-side development, greatly improving the flexibility of user experience and cross-platform development.

How to merge array elements with the same ID into one object in JavaScript? When processing data, we often encounter the need to have the same ID...

In-depth discussion of the root causes of the difference in console.log output. This article will analyze the differences in the output results of console.log function in a piece of code and explain the reasons behind it. �...

Discussion on the realization of parallax scrolling and element animation effects in this article will explore how to achieve similar to Shiseido official website (https://www.shiseido.co.jp/sb/wonderland/)...

Learning JavaScript is not difficult, but it is challenging. 1) Understand basic concepts such as variables, data types, functions, etc. 2) Master asynchronous programming and implement it through event loops. 3) Use DOM operations and Promise to handle asynchronous requests. 4) Avoid common mistakes and use debugging techniques. 5) Optimize performance and follow best practices.

Explore the implementation of panel drag and drop adjustment function similar to VSCode in the front-end. In front-end development, how to implement VSCode similar to VSCode...
