Warning: error_log(/data/www/wwwroot/hmttv.cn/caches/error_log.php): failed to open stream: Permission denied in /data/www/wwwroot/hmttv.cn/phpcms/libs/functions/global.func.php on line 537 Warning: error_log(/data/www/wwwroot/hmttv.cn/caches/error_log.php): failed to open stream: Permission denied in /data/www/wwwroot/hmttv.cn/phpcms/libs/functions/global.func.php on line 537
著互聯網的發展,網頁的視覺效果越來越重要。為了吸引用戶的注意力和提升用戶體驗,頁面動態效果成為了不可或缺的一部分。JavaScript作為一種前端開發語言,可以幫助我們實現各種各樣的頁面動態效果。本文將介紹一些常見的頁面動態效果,并提供實例代碼供參考。
一、利用CSS和JavaScript實現簡單的動態效果
1.1 利用CSS過渡效果實現淡入淡出效果
通過CSS的transition屬性和JavaScript的classList方法,可以實現元素的淡入淡出效果。下面是一個實例代碼:
<!DOCTYPE html>
<html>
<head>
<style>
.fade-in {
opacity: 0;
transition: opacity 1s ease-in-out;
}
.fade-in.show {
opacity: 1;
}
</style>
</head>
<body>
<button onclick="fadeIn()">淡入</button>
<button onclick="fadeOut()">淡出</button>
<div id="box" class="fade-in">Hello, World!</div>
<script>
function fadeIn() {
var box = document.getElementById("box");
box.classList.add("show");
}
function fadeOut() {
var box = document.getElementById("box");
box.classList.remove("show");
}
</script>
</body>
</html>
1.2 利用CSS動畫實現元素的旋轉效果
通過CSS的@keyframes規則和JavaScript的classList方法,可以實現元素的旋轉效果。下面是一個實例代碼:
<!DOCTYPE html>
<html>
<head>
<style>
.rotate {
animation: spin 2s infinite linear;
}
@keyframes spin {
from { transform: rotate(0deg); }
to { transform: rotate(360deg); }
}
</style>
</head>
<body>
<button onclick="rotate()">旋轉</button>
<div id="box">Hello, World!</div>
<script>
function rotate() {
var box = document.getElementById("box");
box.classList.toggle("rotate");
}
</script>
</body>
</html>
二、利用JavaScript實現更復雜的動態效果
2.1 實現元素的平移和縮放
通過JavaScript修改元素的樣式屬性,可以實現元素的平移和縮放效果。下面是一個實例代碼:
<!DOCTYPE html>
<html>
<head>
<style>
#box {
width: 100px;
height: 100px;
background-color: red;
position: relative;
transition: transform 1s ease-in-out;
}
</style>
</head>
<body>
<button onclick="translate()">平移</button>
<button onclick="scale()">縮放</button>
<div id="box"></div>
<script>
function translate() {
var box = document.getElementById("box");
box.style.transform = "translate(100px, 100px)";
}
function scale() {
var box = document.getElementById("box");
box.style.transform = "scale(2)";
}
</script>
</body>
</html>
2.2 實現元素的顏色變化
通過JavaScript修改元素的樣式屬性,可以實現元素的顏色變化效果。下面是一個實例代碼:
<!DOCTYPE html>
<html>
<head>
<style>
#box {
width: 100px;
height: 100px;
background-color: red;
transition: background-color 1s ease-in-out;
}
</style>
</head>
<body>
<button onclick="changeColor()">改變顏色</button>
<div id="box"></div>
<script>
function changeColor() {
var box = document.getElementById("box");
box.style.backgroundColor = "blue";
}
</script>
</body>
</html>
三、注意事項與最佳時間
3.1 優化性能
在實現動態效果時,要注意優化性能,避免因頻繁的DOM操作導致頁面卡頓。可以使用節流函數來限制事件的觸發頻率,減少不必要的DOM操作,提高頁面性能。
3.2 兼容性考慮
在使用JavaScript實現動態效果時,要考慮不同瀏覽器的兼容性。可以使用現代化的JavaScript庫或框架來解決兼容性問題,比如jQuery、React等。
結語:
通過本文的介紹,相信你已經掌握了一些利用JavaScript實現網頁動態效果的技巧。記住要優化性能,考慮兼容性,并創造炸裂的動態效果來吸引用戶的注意。
(內容僅供參考)
Java實現根據svg模版動態生成圖片
需要Java語言動態生成圖片
用流程圖簡單說明下我這邊工作中使用的場景
僅供參考
所以這里就需要生成證書了
我先給大家看下最終實現的圖片效果
這里要先說明一下
下面說下我是如何解決的
這種方式是不能實現這個需求的
這個的原理就是對網頁截圖 但只能對于靜態頁面截圖 不能根據不同的參數值動態生成圖片
所以不提倡使用這種方式
但也介紹下這種使用方式 朋友們根據自己的實際需求情況有選擇的使用
這是h5代碼
test文件夾下面的內容
安裝一個docker nginx 將test文件夾加載到nginx容器的/usr/share/nginx/html目錄下面
docker run --name nginx80 -p 8000:80 -v /tmp/test:/usr/share/nginx/html -d docker.io/nginx
訪問的頁面效果
這張圖片是截圖生成的圖片 但url中的id值并沒有傳給頁面
在h5代碼中請求后端接口獲取數據動態顯示出來也是不可以的
所以這種方式使用局限性很窄
大致原理是 通過http請求該url獲取該url的文件流然后解析h5代碼生成圖片
其實現原理大致為 讀取svg document h5代碼 將動態參數map解析到h5代碼中 轉換成字節數組 生成圖片格式
我本地是mac系統沒有這個問題 在發布到測試環境linux系統出現了這個問題
先看下問題的現象
看到了沒 生成的圖片中文全是亂碼
原因是因為linux系統沒有中文字體
既然linux系統沒有中文字體 那么就安裝它嘛 let's 盤它!!!
brew install fontconfig
fc-list :lang=zh (注意‘:’前的空格)
mac環境默認會安裝很多中文字體
yum -y install fontconfig
fc-list :lang=zh
果然沒有中文字體
a 先在mac系統中找到字體安裝目錄
/System/Library/Fonts
b 找到宋體對應的文件
c 將該文件上傳到linux指定的目錄下
/usr/share/fonts/chinese
d 賦予文件夾操作權限
chmod -R 755 /usr/share/fonts/chinese
e 安裝ttmkfdir來搜索目錄中所有的字體信息,并匯總生成fonts.scale文件
yum -y install ttmkfdir
ttmkfdir -e /usr/share/X11/fonts/encodings/encodings.dir
vi /etc/fonts/fonts.conf
添加
<dir>/usr/share/fonts/chinese</dir>
fc-cache
a 找到jdk所在的安裝目錄
echo $JAVA_HOME
b 將宋體文件復制過來
cp /usr/share/fonts/chinese/STHeiti\ Light.ttc /usr/local/software/jdk1.8.0_141/jre/lib/fonts/fallback
fallback代表存放后備語言的文件夾
https://gitee.com/pingfanrenbiji/resource/tree/master/image
注意: 引入的依賴問題
<!--phantomjs -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.53.1</version>
</dependency>
<dependency>
<groupId>com.github.detro</groupId>
<artifactId>ghostdriver</artifactId>
<version>2.1.0</version>
</dependency>
<!--svg-->
<dependency>
<groupId>com.github.hui.media</groupId>
<artifactId>svg-core</artifactId>
<version>2.5</version>
</dependency>
這些依賴jar包我是上傳到了公司的私服上了
若是朋友們下拉不下來
我提供給大家這些底層jar包的實現源碼
https://gitee.com/pingfanrenbiji/quick-media
自行上傳到自己的私服即可
//html 布局
<view v-html="html">
{{html}}
</view>
//動態生成的元素
<view class="btngo" @tap="handleLink(`${ajaxlink}`)" >
去報名
</view>
//然后scoped的.btngo不生效,因為v-html創建的DOM內容不受作用域內的樣式影響,
//于是我們仍然可以通過深度作用選擇器來為他們設置樣式。
::v-deep {
.btngo{
display: inline-block;
width: 200px;
height: 44px;
line-height: 44px;
background-image: linear-gradient(180deg, #62AFFF 0%, #007BFF 100%);
}
}
讓我醍醐灌頂的兩種解決方法,我選擇了第2種。
*請認真填寫需求信息,我們會在24小時內與您取得聯系。