前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >分享自己开发APP时的实用代码

分享自己开发APP时的实用代码

作者头像
云白去时衣
发布2022-02-11 11:22:41
7550
发布2022-02-11 11:22:41
举报
文章被收录于专栏:白衣博客白衣博客

通过JS实现悬浮球

代码语言:javascript
复制
加载Js([[var btn=document.createElement("div");
var t=document.createTextNode("➜");
btn.style = 'position: fixed;width: 50px;height: 50px;line-height: 50px;border-radius: 50%;bottom: 20px;right: 20px; text-align: center;background-color:white;box-shadow: 0 2px 10px rgba(0,0,0,.5);cursor: pointer; z-index: 1051;';
btn.onclick=function(){window.location.href="https://baidu.com/";};
btn.appendChild(t);
document.body.appendChild(btn);]])

JS代码使网页主体上移

代码语言:javascript
复制
document.body.style.marginTop='-100px'

加载本地网页路径

代码语言:javascript
复制
加载网页("file://"..activity.getLuaDir().."/index.html")

JS点击网站元素触发功能

代码语言:javascript
复制
加载Js('document.getElementsByClassName("iconfont icon-search")[0].click();')

JS插入CSS以改变字体style

代码语言:javascript
复制
  var elscript = document.createElement("style");
  elscript.innerHTML=` @font-face {
  font-family: "moonbridge";
  src: url("https://ku.oioweb.cn/Resources/font/造字工房悦圆/moonbridge.woff2") format("woff2"),
url("https://ku.oioweb.cn/Resources/font/造字工房悦圆/moonbridge.woff") format("woff"),
url("https://ku.oioweb.cn/Resources/font/造字工房悦圆/moonbridge.ttf") format("truetype"),
url("https://ku.oioweb.cn/Resources/font/造字工房悦圆/moonbridge.eot") format("embedded-opentype"),    url("https://ku.oioweb.cn/Resources/font/造字工房悦圆/moonbridge.svg") format("svg"),
url("https://ku.oioweb.cn/Resources/font/造字工房悦圆/moonbridge.otf") format("opentype");
  font-weight: normal;
  font-style: normal;
font-display: swap;
}
body{
    font-family: 'moonbridge'
}
`
elscript.setAttribute("type","text/css");
document.head.appendChild(elscript);

循环检测无网络退出

代码语言:javascript
复制
php = 1000
function net()
task(1,function()
if (php > 1) then
php=php-1
local wl=activity.getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE).getActiveNetworkInfo(); 
if wl== nil then
退出页面()
end
else
end
net()
end)
end
net()

隐藏导航栏

代码语言:javascript
复制
activity.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
activity.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION|View.SYSTEM_UI_FLAG_IMMERSIVE)

判断首次启动执行事件

代码语言:javascript
复制
--首次启动弹出窗口的代码
function getData(name,key)
  local data=this.getApplicationContext().getSharedPreferences(name,0).getString(key,nil)
  return data
end

function putData(name,key,value)
  this.getApplicationContext().getSharedPreferences(name,0).edit().putString(key,value).apply()--3255-2732
  return true
end

if not getData("welcome","启动过了") then
  putData("welcome","启动过了","启动过了")
--事件
else
--事件
end

CSS渐变代码

代码语言:javascript
复制
width: 200px;height: 150px;background: linear-gradient(red, white);

CSS圆角

代码语言:javascript
复制
border-radius: 20px;
border-bottom-right-radius: 20px; border-top-right-radius: 20px;
border-top-left-radius: 20px; border-bottom-left-radius: 20px;
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 通过JS实现悬浮球
  • JS代码使网页主体上移
  • 加载本地网页路径
  • JS点击网站元素触发功能
  • JS插入CSS以改变字体style
  • 循环检测无网络退出
  • 隐藏导航栏
  • 判断首次启动执行事件
  • CSS渐变代码
  • CSS圆角
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档