# BannerAdvertising
Weixin Mini Program Ad Traffic Master Operating Instructions: Document Address Developers can use the ad component to create a banner ad component. The banner ad component automatically pulls the ad data and displays it when created.
# Advertising Size Settings
Banner ads are not allowed to set style properties directly. The default width is 100% (width: 100%) and the height is automatically proportional, so developers can set the width of the outer components of the ad to resize the ad. The width of the outer component of the ad is not allowed to be less than 300px, and when the width is less than 300px, the width of the banner ad is forced to be adjusted to 300px.
/* 外层组件的宽度可设置成100%或具体数值 */
.adContainer {
width: 100%;
}
<view class="adContainer">
<ad unit-id="xxxx"></ad>
</view>
# Advertising incident listening
Banner ads are automatically pulled when created.Developers can use the ad component toonloadandonerrorevent listening ads pull successfully or fail, and can be closed byoncloseeventlistening ads.
<view class="adContainer">
<ad unit-id="xxxx" bindload="adLoad" binderror="adError" bindclose="adClose"></ad>
</view>
Page({
adLoad() {
console.log('Banner 广告加载成功')
},
adError(err) {
console.log('Banner 广告加载失败', err)
},
adClose() {
console.log('Banner 广告关闭')
}
})
# Ads are refreshed on a regular basis
Developers can use thead-intervalsparameter to enable the timed refresh of the ad when creating a Banner ad, and thead -intervals]]parameter is a number type in seconds.Note: The automatic refresh interval cannot be less than 30 seconds, so the parameter value ofad-intervalsmust be greater than or equal to 30.
<view class="adContainer">
<ad unit-id="xxxx" ad-intervals="30"></ad>
</view>